我希望当玩家拒绝时说再见然后结束,而转至选择类别。有什么建议吗?
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")
这个问题有所不同,因为它没有询问循环,而是询问如何正确结束程序。
答案 0 :(得分: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.")