简体   繁体   English

Python Fruit Machine-循环回到输入

[英]Python Fruit Machine - Looping back to input

I need to make a fruit machine in Python. 我需要用Python制作水果机。 The fruits/items spinning are Cherry, Lemon, Bell, Star and Skull. 旋转的水果/物品为樱桃,柠檬,钟形,星形和头骨。 The Success criteria is • 成功标准是•

• If two symbols are rolled the user wins 50p. •如果滚动两个符号,则用户赢得50p。

• If two skulls are rolled user loses £1, if three skulls are rolled loses all money. •如果两个头骨都翻了,用户将损失1英镑,如果三个头骨都翻了,则用户将损失所有钱。

• If you get 3 of the same you get £1, if 3 bells rolled £5. •如果您得到3个相同的东西,您将得到£1,如果3个钟声响起了£5。

• Starts with £1, each go costs 20p. •以1英镑开始,每次比赛费用为20便士。

How do I loop it back to the question "Roll" or "Quit" and how do I make it so that is a user enters something other than roll or quit it says "Oops try again"? 如何将其循环回到“滚动”或“退出”问题,以及如何使用户输入除滚动或退出以外的其他内容,并显示“糟糕,请重试”? - Please explain any changes to the code as I just know the basics. -请解释一下对代码的任何更改,因为我只知道一些基础知识。

You can wrap your program in an infinite loop like this: 您可以将程序包装在一个无限循环中,如下所示:

while True:
    start = input("Enter Roll or Quit? ")
    # [more code]

This way, your program will always start over. 这样,您的程序将始终重新开始。 If you get an invalid input use continue to jump back to the beginning of the loop to get another input. 如果输入无效,请continue跳回到循环的开头以获取另一个输入。 If the user wants to quit use break to exit the loop. 如果用户要退出,请使用break退出循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM