96. Python Program to Ask Again Until the Age Is Valid
EasyInput loops
Overview
Keep asking until the answer is valid, instead of giving up after the first mistake.
Problem Statement
Read an age (a whole number). A valid age is from 1 to 120. While the age is not valid, print Invalid age, try again and read it again. When it is valid, print it. For example, for 0, 150 and 30:
Invalid age, try again
Invalid age, try again
Your age is 30
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
One value per line; the last line is always a valid age. Example:
0
150
30
Output
The output for that example:
Invalid age, try again
Invalid age, try again
Your age is 30
The tests try 4 different inputs, including the edges 1 and 120.