首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我该如何提出一个问题,如果回答错误会给你另一次机会?

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

Stack Overflow用户
提问于 2019-01-15 21:05:03
回答 1查看 63关注 0票数 1

我正在尝试制作一个基于脚本的故事,灵感来自于黑镜: Bandersnatch。这是我第一次使用Python或其他脚本程序,所以我真的很糟糕。这是我写的:

代码语言:javascript
复制
  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,重新开始这个问题。我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2019-01-15 21:21:12

试试这样的东西。它将重复您的问题,直到您输入其他内容,在本例中为“window”。只需为其他选项编写逻辑即可。

代码语言:javascript
复制
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时,它将从循环中消失。就这么简单

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54199445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档