【问题标题】:How to end a python program without it going to the next line of code [duplicate]如何在不进入下一行代码的情况下结束python程序[重复]
【发布时间】:2019-09-20 21:25:22
【问题描述】:

我希望当玩家拒绝时说再见然后结束,而是转到选择一个类别。有什么建议吗?

while True:
    choice = input ("Do you want to play?")
    if choice == "yes": 
        print("Great!")
        break # Go to the game
    elif choice == "no":
        print("Goodbye.")
        break # nothing
    else:
        print("Please answer yes or no.")


continent = input("Choose a category: \n"
              "Africa \n"
              "Asia \n"
              "Antarctica \n"
              "Australia \n"
              "Europe \n"
              "North America \n"
              "South America \n")

这个问题不同,因为它不是询问循环,而是询问如何正确结束程序。

【问题讨论】:

  • 你提到的循环在哪里?

标签: python python-3.x if-statement while-loop


【解决方案1】:
while True:
    choice = input ("Do you want to play?")
    if choice == "yes" 
        print("Great!")
        break # Go to the game
    elif choice == "no" 
        print("Goodbye.")
        break # nothing
    else:
        print("Please answer yes or no.")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 2021-09-11
    • 1970-01-01
    • 2016-08-14
    • 2018-08-13
    • 1970-01-01
    • 2014-05-03
    相关资源
    最近更新 更多