我如何提出一个问题,如果回答错误会给您另一个机会?

时间:2019-01-15 13:05:03

标签: python

我正在尝试制作一个受黑镜启发的剧本故事:班德斯纳奇。这是我第一次使用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并重新开始问题。我该怎么做呢?

1 个答案:

答案 0 :(得分:0)

尝试类似这样的方法。它将重复您的问题,直到您输入其他内容(在本例中为“窗口”)为止。 只需为其他选项编写逻辑。

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时,它将从循环中消失。就这么简单