Checking user input using isnan function of NumPy
问题 I'm trying to use NumPy to check if user input is numerical. I've tried using: import numpy as np a = input("\n\nInsert A: ") if np.isnan(a): print 'Not a number...' else: print "Yep,that's a number" On its own t works fine, however when I embed it into a function such as in this case: import numpy as np def test_this(a): if np.isnan(a): 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) Then