【发布时间】:2015-02-20 12:29:47
【问题描述】:
from sys import exit
def gold_room():
print "This room is full of gold. How much do you take?"
next = raw_input("> ")
if "0" in next or "1" in next:
how_much = int(next)
else:
dead("Man, learn to type a number.")
if how_much < 50:
print "Nice, you're not greedy, you win!"
exit(0)
else:
dead("You greedy bastard!")
def dead(why):
print why, "Good job!"
exit(0)
gold_room()
为什么我输入 2~9 会变成“伙计,学习输入数字” 输入 10~49 结果是“很好,你不贪心,你赢了!” 谢谢大家
【问题讨论】:
-
"0" in next or "1" in next检查输入中是 0 还是 1。 1 和 0 都在10~49中,并且都不在2~9中。你想发生什么? -
尝试检查
next.isdigit()。
标签: python