对“你发烧了吗?”说“n”输出False而不是提示我回答“你有鼻塞吗?”。其他其他陈述有效。说“你”说“你发烧了吗?”,“n”说“你有皮疹吗?”,“n”说“你的耳朵受伤吗?”打印“流感”。我无法弄清楚为什么其他声明不起作用。
def part3():
if(raw_input("Do you have a fever? (y/n): ") == "y"):
if(raw_input("Do you have a rash? (y/n): ") == "y"):
print "Measles"
else:
if(raw_input("Does your ear hurt? (y/n): ") == "y"):
print "Ear Infection"
else:
print "Flu"
else:
if(raw_input("Do you have a stuffy nose? (y/n): " == "y")):
print "Head Cold"
else:
print "Hypochondriac"
答案 0 :(得分:10)
我发现了你的错误,你会为此而讨厌自己。这一行
if(raw_input("Do you have a stuffy nose? (y/n): " == "y")):
应该是
if(raw_input("Do you have a stuffy nose? (y/n): ") == "y"):
更多地解释为什么它打印错误: “你有鼻塞吗?(是/否):”==“y” 被评估为False,所以就像说 的raw_input(假) 这将打印“False”,但仍然得到输入