#Functions go here def num_check(question, num_type, exit_code=None): """Checks user enter an integer / float that is more than zero (or the optional exit code)""" if num_type == "integer": error = "Opps - please enter an integer more than zero." change_to = int else: error = "Opps - please enter a number more than zero." change_to = float while True: response = input(question).lower() # checks for the exit code if response == exit_code: return response try: response = change_to(response) if response > 0: return response else: print(error) except ValueError: print(error) # Main routine #loop for testing purposes... while True: print() my_float = num_check("Please enter a number more than zero. ", "float") print(f"Thanks. You chose ({my_float})") print() my_int = num_check("Please enter an integer more than zero. ", "integer", "") if my_int == "": print("You have chosen infinite mode.") else: print(f"Thanks. You chose {my_int}.")