【发布时间】:2018-08-21 22:02:28
【问题描述】:
我需要编写一个 if 语句来接受用户输入并接受整数。
这是代码,但它只取指定的整数。
next = raw_input("> ")
if "0" in next or "1" in next:
how_much = int(next)
【问题讨论】:
-
试试
if next.IsNumeric(): -
您描述了一种情况并发布了一些代码。您想问我们什么问题?
-
@emsimpson92:没有
IsNumeric方法,isnumeric表示错误的东西。 -
@user2357112 而且在 Python 2.7 中也不存在。
-
关键是
try:做那个how_much = int(next),except ValueError:在这种情况下做任何你想做的事情。
标签: python