Age Category
Programming Basics · Python
TASK
Problem
Print `CHILD` for 0–12, `TEEN` for 13–17, `ADULT` for 18–64, and `SENIOR` for 65+.
EXAMPLE
Example
17
TEEN
LIMITS
Constraints
0 ≤ age ≤ 120
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `int()` converts a numeric string into an integer. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `if` checks a condition and runs its block when the condition is true. `else` runs when the corresponding `if` condition is false. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** An `if` statement chooses a program branch from a Boolean condition. Comparisons produce `True` or `False`, and `elif` lets you test several mutually exclusive cases in order. The expression `'CHILD'` shows how this idea is applied to the task data.
For this task, pay special attention to `int(input())`: it connects the concept above to the concrete computation or program action.
**Focus: “Age Category”.** The same basic mechanism is used in a different context here, so understand the operation itself rather than memorizing a finished line of code.
NEED HELP?
Hints
+
['Check upper bounds in ascending order.']
ANSWER
Solution
+
a = int(input())
if a <= 12:
print('CHILD')
elif a <= 17:
print('TEEN')
elif a <= 64:
print('ADULT')
else:
print('SENIOR')