Exercise 4: Ask Again Until the Age Is Valid — Possible Solution ==================================================================== while True: text = input("Enter your age: ") if not text.isdigit(): print("Digits only, please") continue age = int(text) if age > 120: print("That age is not realistic") continue print(f"Age recorded: {age}") break Example run: Enter your age: abc Digits only, please Enter your age: -5 Digits only, please Enter your age: 200 That age is not realistic Enter your age: 34 Age recorded: 34 WHY THIS WORKS AS AN ANSWER ------------------------------ The checks happen in a safe order: isdigit() first, because int() on text such as 'abc' would raise ValueError, then the range check on the converted number. Each failed check prints a message and continues, which sends control back to the input() line for another try. Only a value that passes both checks reaches the print and the break. isdigit() also rejects '-5' (because of the minus sign) and '' (empty), so negative and empty input are caught by the first check, which is why only a maximum needs a separate test.