Determining Your Age
This program determines if a person is an infant, child, teenager or an adult while using conditional and control flow. First I used the input method to ask the user what their age is, then used the int method to change the user’s input into an integer. I stored that information into the variable age. If the person’s age is less than 1, they are an infant, if their age is greater than 1 but less than 12 they are a child, age is greater than 12 but less than 17 they are a teen, age is greater than 17 and less than 64 they are an adult, if their age is greater than 64 they are a senior. Anything else inputted will return “Please enter a valid age!”.
def age():
print(‘Hello!’);
age = int(input(‘Please enter your age as an integer:’))
if age <= 1:
print(‘You are an infant!’)
elif age > 1 and age <= 12:
print(‘You are a child!’)
elif age > 12 and age <= 17:
print(‘You are a teen!’)
elif age > 17 and age <= 64:
print(‘You are an adult!’)
elif age >= 64:
print(‘You are a senior!’)
else:
print(‘Please enter a valid age!’)
age()