我不知道为什么我必须输入q
n次生成的问题才能退出程序,当我只输入q
一次时,我应该怎么做才能使程序立即关闭
greetings = input("Hello, what should i call you? ")
def generate_again_or_quit():
while True:
option = input("Press any key to generate another question or Q to exit" ).lower()
if option == "q":
break
generate_questions()
def generate_questions():
print(random_questions_dict.get((random.randint(1, 30))))
generate_again_or_quit()
while True:
greetings2 = input("Do you want me to generate some questions "+greetings+"?").lower()
if greetings2 == "yes":
generate_questions()
break
elif greetings2 == "no":
print("See you later...")
break
else:
print("Please answer with yes or no")
continue
如注释所示,选择迭代或递归。下面是一个递归示例
相关问题 更多 >
编程相关推荐