我正在用python3.4.3创建一个基于文本的冒险游戏,我不知道如何让代码重复一个问题。如果这有助于理解发生了什么的话,在这之前有一大堆的叙述。你知道吗
print("\n\n\n\n\nYou awake to find yourself in the center of a clearing in a forest.")
print("You stand up and decide to take a look around.")
str = input("Which direction do you steer your head? d= down, l= left, r= right, u= up, b= behind you: ")
print(" ")
if str in ("d"):
print("You see your combat boots and the grassy ground below your feet. ")
if str in ("l"):
print("The forest trees grow thicker and darker that way. You stare into the shadows and feel... cold...")
if str in ("r"):
print("The forest is warm and inviting that way, you think you can hear a distant birds chirp.")
if str in ("u"):
print("The blue sky looks gorgeous, a crow flies overhead... that's not a crow...")
print("It's a Nevermore, an aerial Grim. You stand still until it passes.")
if str in ("b"):
print("the grass slowly grows to dirt as the area falls into a mountain cliff. You now know where you are.")
print("Mount Glenn, one of the most Grim-infested places in all of Remnant.")
print("It's a bit unsettling.")
else:
print("Try that again")
我希望代码向用户重复这个问题,直到他们回答了所有可能的答案,然后继续下一个问题。我还想让它在他们得到其他东西时重复这个问题。我该怎么做?你知道吗
不要使用
str
作为变量名,它会隐藏一个重要的内建项并导致奇怪的问题。你知道吗使用while循环将输出限制为有效选项。你知道吗
另请参见:
基本上,你可以把你的问题放在一个循环中,反复循环,直到你输入一个想要的“如果”案例。我修改了你的代码如下。请看一看
这样做:
相关问题 更多 >
编程相关推荐