type(a) != int == False
is a chained comparison, and evaluates as:
(type(a) != int) and (int == False)
int == False
is always going to be false.
Don't use == False
or == True
in boolean tests; just test directly or use not
. Also, use isinstance()
to test for specific types:
if isinstance(a, int):
# ...
However, raw_input()
returns an object of type str
, always. It won't produce an object of type int
or float
. You need to convert explicitly using float()
, and then use exception handling to handle inputs that are not valid integer or floating point numbers:
try:
result = float(a)
print 'Input verified'
except ValueError:
print 'Sorry, I need a number'
Also see Asking the user for input until they give a valid response