我正在尝试制作一个基于脚本的故事,灵感来自于黑镜: Bandersnatch。这是我第一次使用Python或其他脚本程序,所以我真的很糟糕。这是我写的:
print("Hello! I'm your personal A.I. ")
q1 = input("Are you sure you want to begin this journey? (yes/no)")
if not q1 == "yes":
print("Okay. Have a nice day")
exit()
if q1 == "yes":
print("You have chosen to begin this journey. Do not be sure you will make it to the end.")
from time import sleep
sleep(5)
print(
)
print("You are in an old house. It's dark. You look around.")
c1 = ("There is a dirty window to your left. "
)
c2 = ("In front of you there is a door. Light is coming from underneath."
)
c3 = ("There is also a staircase to your right."
)
q2 = input("Which one do you choose to go to? (window/door/staircase)")
if q2 == "window":
print("You go over to the window. You try to look out but you can't see anything."
)
print("You go back")这就是我需要帮助的地方。我需要回到c1,重新开始这个问题。我该怎么做呢?
发布于 2019-01-15 21:21:12
试试这样的东西。它将重复您的问题,直到您输入其他内容,在本例中为“window”。只需为其他选项编写逻辑即可。
while True:
q2 = input("Which one do you choose to go to? (window/door/staircase)")
if q2 == "window":
print("You go over to the window. You try to look out but you can't see anything."
)
print("You go back")
continue
else:
break当涉及到continue时,它将再次从while循环的开始进行。当它涉及到break时,它将从循环中消失。就这么简单
https://stackoverflow.com/questions/54199445
复制相似问题