如何使我的python代码返回循环
我对python非常陌生,我正在尝试通过制作一个简单的游戏来学习。我希望用户能够输入他们的操作,然后如果他们选择不太继续,他们将被发送回再次输入的阶段。我已经尽了最大的努力,但一旦他们选择不“继续”,他们就不能再选择我列出的任何其他选项 谢谢你的帮助如何使我的python代码返回循环,python,loops,if-statement,while-loop,Python,Loops,If Statement,While Loop,我对python非常陌生,我正在尝试通过制作一个简单的游戏来学习。我希望用户能够输入他们的操作,然后如果他们选择不太继续,他们将被发送回再次输入的阶段。我已经尽了最大的努力,但一旦他们选择不“继续”,他们就不能再选择我列出的任何其他选项 谢谢你的帮助 print ("How do you proceed?") print ("Do you Shout? Look? Continue?") action1 = input() if action1 == ("Continue"): #Contin
print ("How do you proceed?")
print ("Do you Shout? Look? Continue?")
action1 = input()
if action1 == ("Continue"): #Continue to next section
print ("You continue on throught the darkness untill you reach a cold stone wall")
pass
elif action1 == "Shout":
print ("In the dark noone can hear you scream.")
elif action1 == ('Look'):
print ("'I cannae see anything in the dark' you think to yourself in a braod Scottish accent.")
while action1 != ("Continue"):
print ("Enter your next action.(Case sensitive!!)")
print ("Shout? Look? Continue?")
action1 = input() #Want this too loop back to start of action menu
如果用户输入有效,您可以将整个过程放入一个
while
循环中并中断循环:
print("How do you proceed?")
while True:
print("Do you Shout? Look? Continue?")
action1 = input()
if action1 == "Continue": # Continue to next section
print("You continue on throught the darkness untill you reach a cold stone wall")
break # break out of the while loop
elif action1 == "Shout":
print("In the dark none can hear you scream.")
elif action1 == 'Look':
print("'I cannot see anything in the dark' you think to yourself in a broad Scottish accent.")
print("Enter your next action.(Case sensitive!!)")
# You'll land here after the break statement