如何结束一个python程序而不进入下一行代码

如何结束一个python程序而不进入下一行代码,python,python-3.x,if-statement,while-loop,Python,Python 3.x,If Statement,While Loop,我想当一个玩家说“不”的时候,他会说“再见”,然后结束,但他会选择一个类别。有什么建议吗 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 # no

我想当一个玩家说“不”的时候,他会说“再见”,然后结束,但他会选择一个类别。有什么建议吗

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")

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

你提到的循环在哪里?
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.")