【发布时间】:2013-06-09 07:28:21
【问题描述】:
我是一名自学成才的程序员,我刚开始使用 python。当我执行这段代码时,我遇到了一点问题:
x = 0
while x == 0:
question = raw_input("Would you like a hint? ")
if question == "y" or "yes":
print "Ok"
first.give_hint("Look over there")
x = 1
elif question == "n" or "no":
print "Ok"
x = 1
else:
print "I'm Sorry, I don't understand that"
您知道,first.give_hint("Look over there") 是在程序早期的一个类中定义的,我只是为了空间而省略了这部分。当我运行程序时,无论我输入什么,我都会得到第一个案例“往那边看”,我一直在试图找出问题所在,但我就是不明白。如果你们能帮助我,我将不胜感激。
【问题讨论】:
-
除了答案,还可以考虑
if question.lower() in ["y", "yes"]: -
是的,这就是“防弹”方式。
标签: python loops if-statement while-loop