我試圖使用numpy的檢查,如果用戶輸入數值,我用已經試過:NumPy的 - 使用isnan(x)的
from numpy import *
a = input("\n\nInsert A: ")
if isnan(a) == True:
print 'Not a number...'
else:
print "Yep,that's a number"
它自己和然而,當它工作得很好,我它嵌入到一個函數,例如在這種情況下:從numpy的進口
*
def test_this(a):
if isnan(a) == True:
print '\n\nThis is not an accepted type of input for A\n\n'
raise ValueError
else:
print "Yep,that's a number"
a = input("\n\nInsert A: ")
test_this(a)
然後我得到一個NotImplementationError說這是不是這種類型的實現,誰能解釋這是不工作?
任何幫助將不勝感激,再次感謝。
是您的目標是測試是否值輸入的用戶是一個有效的數字? – 2011-12-14 16:00:14