# Checks that a user input is a valid number def int_check(question, low, high, error_type): while True: # changes error message based on error_type if error_type == 1: error = f"Please enter a number between {low} and {high}" else: error = 'Please enter a number' to_check = input(question) try: response = int(to_check) # checks that the number is between low and high if low <= response <= high: return response else: print(error) except ValueError: try: if error_type == 1: response = int(to_check) # checks that the number is between low and high if low <= response <= high: return response else: print(error) else: response = float(to_check) # checks that the number is between low and high if low <= response <= high: return response else: print(error) except ValueError: print(error)