[英]How to make it my code go back to a specific while loop in python?
[英]How to make my python code loop back
我真的是python的新手,我试图通过制作一个简单的游戏来学习。 我希望用户能够输入他们的操作,然后,如果他们选择不太继续,他们将被送回到再次输入的阶段。 我已尽力进行了尝试,但是一旦他们选择不“继续”,他们将无法再选择我提出的任何其他选项。
感谢帮助。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.