def num_check(question, low, high): """Checks user enters a number (integer or float) between low and high inclusive.""" error = f"Oops - please enter a number between {low} and {high}." while True: try: response = float(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) #main loop goses here while True: print() my_num = num_check(f"chose a number",1,20000) print(f"You chose {my_num}")