def answer_check(question): while True: error = "Please enter an integer that is 1 or more." if question == "xxx": break to_check = input(question) # check for infinite mode if to_check == "": return error elif to_check == "xxx": break try: response = int(to_check) # check that the number is more than / equal to 1 if response < 1: print() print(error) print() elif response == "xxx": break except ValueError: print() print(error) print() test = answer_check("What is the number? ") print(test)