You can expand on that:
# safe numeric input function
# all() needs Python25 or higher
def input_num(prompt="Enter number: "):
"""
prompt the user for numeric input
prompt again if the input is not numeric
return integer or float
"""
while True:
# coded for Python3, Python2 uses raw_input()
# strip() removes any leading or trailing whitespace
num_str = input(prompt).strip()
# make sure that all char are of typical number
if all(c in '+-.0123456789' for c in num_str):
break
# float contains period (US)
if '.' in num_str:
return float(num_str)
else:
return int(num_str)
# testing ...
n = input_num()
print( n, type(n) )