Python Language Function to prompt user for a number


Example

def input_number(msg, err_msg=None):
    while True:
        try:
            return float(raw_input(msg))
        except ValueError:
            if err_msg is not None:
                print(err_msg)


def input_number(msg, err_msg=None):
    while True:
        try:
            return float(input(msg))
        except ValueError:
            if err_msg is not None:
                print(err_msg)

And to use it:

user_number = input_number("input a number: ", "that's not a number!")

Or, if you do not want an "error message":

user_number = input_number("input a number: ")