【发布时间】:2014-06-01 21:07:51
【问题描述】:
我对 python 中的数学 .isnan() 函数有一点问题。差不多,我有这个代码:
import math
diceChoice = raw_input('Which dice will you throw?\n 4 sides\n 6 sides\n 12 sides?\n>')
if math.isnan(float(diceChoice)):
print(str(diceChoice) + ' is an invalid choice')
如果 diceChoice 不是数字(例如“a”),它会给我错误:
ValueError: could not convert string to float: a
如果我不将它转换为浮点数,它会给我另一个错误,说它需要是一个浮点数。我一定是做错了什么,因为如果 isnan 函数只接受数字,它将毫无用处。有人可以帮我吗
提前致谢
【问题讨论】:
-
提示输入时您在输入什么?
-
我只是在输入字母a
标签: python python-2.7 nan