Validated Age Input
Write a program that repeatedly asks for an age until it receives a valid non-negative whole number, using try/except inside a loop.
What the problem means: keep reading a new line of input every time the previous one was invalid (not a number, or negative), and only stop once a good value arrives.
Approach: loop forever; inside the loop, try to convert the input to int and check it isn't negative — on failure (either a ValueError or a negative value), print the retry message and continue the loop; on success, print the accepted age and break.
Input: One or more lines: each is an attempted age (some may be invalid text or negative numbers); the last line is always a valid non-negative integer.
Output: Please enter a valid number once per invalid attempt, then finally Age accepted: <age>.
abc 25
Please enter a valid number Age accepted: 25
- The final input line is always a valid non-negative integer.
Hint 1
int(raw) raises ValueError if raw isn't a valid whole number — catch it with try/except.
Hint 2
Even if int(raw) succeeds, still check the result isn't negative before accepting it.
Hint 3
Use break to exit the while loop only once a valid, non-negative age has been accepted.
A while True: loop keeps reading input until a valid answer arrives. Each attempt is wrapped in try/except ValueError to catch non-numeric text; a successfully parsed but negative number is rejected with the same message via an explicit check. Only once a valid, non-negative integer is parsed does the loop print the acceptance message and break.