I want to test raw_input
to make sure that the string contains only numbers and at maximum a single decimal point. str.isdigit()
looked promising but it will not return True if there is a decimal point in the string.
Ideally, the code would look like this:
def enter_number():
number = raw_input("Enter a number: ") # I enter 3.5
if number.SOMETHING: # SOMETHING is what I am looking for
float_1 = float(number)
return float_1
else
sys.exit()
half = enter_number() / 2 # = 1.75
double = enter_number() * 2 # = 7