【发布时间】:2017-03-19 11:20:12
【问题描述】:
已解决
当输入一个包含“0”或“4”的整数时,这个if语句只返回语句中的第一个。
例如,在下面的代码中,如果我输入“60”,它将执行:
print "很好,你不贪心——你赢了!"退出(0)
不是
dead("你这个贪婪的混蛋!")
正如我所期望的那样,how_much >= 50。
尝试了很多更改,但似乎无法按预期执行。有人知道这里发生了什么吗?
def gold_room():
print "This room is full of gold. How much do you take?"
number_type = False
while True:
choice = raw_input("> ")
how_much = int(choice)
if "0" in choice or "4" in choice and how_much < 50:
print "Nice, you're not greedy - you win!"
exit(0)
elif "0" in choice or "4" in choice and how_much >= 50:
dead("You greedy bastard!")
else:
print "Man, learn to type a number. Put a 0 or a 4 in your number."
【问题讨论】:
标签: python if-statement while-loop