【发布时间】:2014-08-23 00:37:09
【问题描述】:
不管我给出什么输入,我得到的输出是“我认为你已经长大了去冒险。你的冒险到此结束。” 就像我输入 17 一样,我会得到“我认为你已经长大了去冒险。你的冒险到此结束。”如果我输入 18-59,我会得到“我认为你已经长大了去冒险。你的冒险到此结束。”
while True:
age = raw_input("\n So tell me " + str(name) + ", how old are you?: ")
if age.isdigit() == False:
print "\n Please, put only in numbers!"
time.sleep(3)
elif age < 18:
print "\n %s. A minor. You got to be atleast 18 to go on this adventure. Your adventure ends here." % age
time.sleep(7)
exit(0)
elif age >= 60:
print "\n %s. I think you're to old to go on an adventure. Your adventure ends here." % age
time.sleep(5)
exit(0)
else:
print "\n %s. You're starting to get old." % age
break
【问题讨论】:
-
raw_input每次都会给您一个字符串,因此您无法将其与数字进行比较。试试int(raw_input(...))。
标签: python python-2.7 input while-loop