May-30-2020, 08:07 AM
This is a very common question. At the same time, the answer is not obvious because it forces you to use the exceptions mechanism.
Here is one way to do it
Here is one way to do it
while True: try: age = int(input("How old are you? ")) except ValueError: print("Invalid value. Please enter an integer! Let's try again...") else: break print("You are {} years old.".format(age))