【发布时间】:2012-07-23 03:57:58
【问题描述】:
我正在尝试获取原始输入并检测它是否在一个范围内。
这是我的代码。
def gold_room():
print "This room is full of gold. How much do you take?"
next = raw_input("> ")
if next == int in range(50):
how_much = int(next)
else:
dead("Man, learn how to type a number.")
if how_much < 50:
print "Nice, you're not greedy, you win!"
exit(0)
else:
dead("You greedy bastard!")
当我输入一个数字时,它会给我一个 else:“伙计,学习如何输入一个数字。”
我猜这行不通是“if next == int in range(50):
谁能帮帮我?
提前致谢!
编辑:
我是个菜鸟,所以那条线只是我在打球。
我想它接下来会检查它是否是数字 0-50 范围内的整数。
【问题讨论】:
-
请解释您认为
next == int in range(50)会做什么。请更新这个表达式的分步解释问题。也许您应该在>>>提示符下尝试一下,以确认它的作用。 -
不要隐藏内置函数
next。 -
“那条线只是我的球停车”。坏习惯。使用
>>>提示,请确认代码做了(或不做)什么。
标签: python