我对编程相当陌生,但我有一个简短的问题。我想写一个“选择你自己的冒险”的游戏,但我遇到了一个问题。我只对代码中的if
语句进行了深入的研究,但我希望能够在用户键入某些内容时将其发送回以前的代码
例如:
print "You are in a room with two doors to either side of you."
choiceOne = raw_input("Which way will you go?")
choiceOne = choiceOne.lower()
if choiceOne = "r" or choiceOne = "right":
print "You go through the right door and find yourself at a dead end."
elif choiceOne = "l" or choiceOne = "left":
print "You go through the left door and find yourself in a room with one more door."
else:
print "Please choose left or right."
在if
语句中,我想将用户发送回choiceOne
的raw_input()
。在elif
语句中,我想给用户一个选择,要么从隔壁继续,要么返回第一个房间,看看另一扇门可能藏着什么秘密。有没有办法做到这一点?我不在乎这条路是否复杂,我只想让它运作起来
使用
while
循环:您需要使用
==
进行比较检查,=
用于赋值要中断循环,可以在循环外添加打印
print "Enter e to quit the game"
:然后在代码中添加:
您正在寻找^{} 循环吗
我认为这个网站解释得很好:http://www.tutorialspoint.com/python/python_while_loop.htm
→
相关问题 更多 >
编程相关推荐