老实说,我不知道为什么这段代码不起作用。当代码运行时,无论我输入什么,它总会返回“再见。祝你有愉快的一天!”谁能明白为什么?
again = raw_input("Would you like to restart? ").lower()
if again == "no" or "n":
print "Goodbye. Have a nice day!"
loop = 0
elif again == "yes" or "y":
loop = 1
else:
print "Answer invalid. Have a nice day!"
loop = 0
(在此之前有一段代码在'loop'变量为0时处于循环中。这就是为什么在'if','elif'和'else'语句之后有循环变量编辑。