def num_check(question, num_type, exit_code=None): if num_type == "integer": error = "oops enter a intger more than 0" change_to = int else: error = "oops enter number more then 0 " change_to = float while True: response = input(question).lower() if response == exit_code: return response try: response = change_to(response) if response > 0: return response else: print(error) except ValueError: print(error) while True: print() my_float = num_check(question="please enter a number more then 0: ", num_type="float") print(f"Thanks. You chose {my_float}") print() my_int = num_check(question="Please enter an integer more then 0: ", num_type="integer", exit_code="") if my_int == "": print("You have chosen infitite mode.") else: print(f"thanks. you chose {my_int}")