Ticket Price
Programming Basics · Python
TASK
Problem
Given passenger age: ticket costs 0 under 6, 50 for 6–17, 100 for 18–64, and 60 for 65+.
EXAMPLE
Example
70
60
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 `0` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Check ages by ascending upper bounds.']
ANSWER
Solution
+
a = int(input())
if a < 6:
print(0)
elif a < 18:
print(50)
elif a < 65:
print(100)
else:
print(60)