Clothes for Weather
Programming Basics · Python
TASK
Problem
Given temperature `t` and rain flag 0/1. Base clothing: JACKET below10, HOODIE below20, else TSHIRT. Append ` UMBRELLA` if rain=1.
EXAMPLE
Example
15 1
HOODIE UMBRELLA
LIMITS
Constraints
rain ∈ {0,1}
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `split()` separates one input line into individual values using spaces. `map()` applies the specified conversion to each input value. The `+` operator adds numbers. 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 `'JACKET'` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Choose clothing first, then use a separate `if` for rain.']
ANSWER
Solution
+
t, r = map(int, input().split())
if t < 10:
ans = 'JACKET'
elif t < 20:
ans = 'HOODIE'
else:
ans = 'TSHIRT'
if r == 1:
ans += ' UMBRELLA'
print(ans)