python if退出_Python if else退出

这是一个聊天回复程序,我目前面临的问题是,如果输入的答案与我的一个答案不匹配,我会尝试让它退出,但由于这三个问题的所有答案都是作为响应放在一起的,所以即使是它随机选择的问题的正确答案也会被输入,python仍然认为这是不对的,因为它没有遇到其他两个,然后它将退出。请告诉我如何才能对这些程序采取不同的方法。谢谢您的帮助1import random

x=input("What is your name? ")

def main():

def feeling():

return input("How are you feeling right now " +str(x)+"? ")

def homesick():

return input("Do you miss your home? ")

def miss():

return input("Who do you miss?")

prompts = [feeling,homesick,miss]

response = random.choice(prompts)()

if response==("tired"):

Tired=['I wish I can make you feel better.','I hope school is not making you feel stressed.','You deserve the right to relax.']

print(random.choice(Tired))

else:

exit()

if response==("yes"):

yes=["Don't worry, you will be home soon......",'I am protecting your family and loved ones, trust me on this.',"Your kingdoms has been waiting for a long time, they'd forgiven your mistakes"]

print(random.choice(yes))

else:

exit()

if response==("my mom"):

print("Mom will be in town soon")

else:

exit()

main()

main()


版权声明:本文为weixin_42398386原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。