Age Validation

Write a program that validates a persons age. The user should be able to enter their age, which should then be checked to ensure it is between 0 and 120. If an incorrect age has been entered, the user should be shown an error message and be asked to enter their age again. Once a valid age has been entered, the age should be displayed back to the user.

Enter your age: 221
Invalid age, please try again.
Enter your age: 21
Your age is 21
RECEIVE age FROM KEYBOARD

WHILE age < 0 OR age > 120 DO
    SEND "Invalid age, please try again." TO DISPLAY
    RECEIVE age FROM KEYBOARD
END WHILE

SEND "Your age is " & age TO DISPLAY
age = int(input("Enter your age: "))

while age < 0 or age > 120:
    print("Invalid age, please try again.")
    age = int(input("Enter your age: "))
    
print("Your age is", age)
# Get age from the user
age = int(input("Enter your age: "))

# Validate if age is between 0 and 120
while age < 0 or age > 120:
    # Display an error message
    print("Invalid age, please try again.")
    # Get age from the user again
    age = int(input("Enter your age: "))

# Display the users age
print("Your age is", age)

Extension

Extend the program to decide if the age makes a person child, teenager, adult or senior.

Enter your age: 551
Invalid age, please try again.
Enter your age: 51
Your age is 51
You are an adult.
Enter your age: 122
Invalid age, please try again.
Enter your age: 12
Your age is 12
You are a child.

Target

You should be able to use While Loops to solve a problem.