首页 > 解决方案 > 无法弄清楚如何在 Python3 中重复过程

问题描述

我正在为一种爱好制作游戏,一种基于冒险文本的游戏。我不知道 id 是如何做到的,所以如果他们键入“起床”以外的任何内容,则该过程会重复,并且代码会再次询问他们,直到他们得到正确的答案。

getup = input("What is your action?: ")
if getup == "Get Up":
    print("You stand up and get your bearings. You scan the enviroment. There is a small passage way to the north, and tight crevis to the east. Everywhere else is just cave wall")
elif getup == "get up":
    print("You stand up and get your bearings. You scan the enviroment. There is a small passage way to the north, and tight crevis to the east. Everywhere else is just cave wall")
elif getup == "Get up":
    print("You stand up and get your bearings. You scan the enviroment. There is a small passage way to the north, and tight crevis to the east. Everywhere else is just cave wall")
elif getup == "GET UP":
    print("You stand up and get your bearings. You scan the enviroment. There is a small passage way to the north, and tight crevis to the east. Everywhere else is just cave wall")
else:
    print("Celsia: You do not have time to waste,",name,"!!. You must Get Up")

标签: pythonpython-3.xrepeat

解决方案


也许使用while循环:

getup = input("What is your action?: ")
while getup.lower()!='get up':
    print("Celsia: You do not have time to waste,",name,"!!. You must Get Up")
    getup = input("What is your action?: ")
print("You stand up and get your bearings. You scan the enviroment. There is a small passage way to the north, and tight crevis to the east. Everywhere else is just cave wall")

推荐阅读