a = raw_input('How much is 1 share in that company? ')
while not a.isdigit():
print("You need to write a number!\n")
a = raw_input('How much is 1 share in that company? ')
仅当用户输入integer
,但我希望它能够工作,即使他们输入float
,但当他们进入string
.
所以用户应该能够输入9
and 9.2
, 但不是abc
.
我该怎么做呢?
EAFP
try:
x = float(a)
except ValueError:
print("You must enter a number")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)