Internet Plan Choice
Programming Basics · Python
TASK
Problem
Given monthly traffic `gb`: choose `S` up to 10 GB, `M` up to 50 GB, otherwise `L`.
EXAMPLE
Example
35
M
LIMITS
Constraints
Physical and monetary quantities that cannot be negative are non-negative; the absolute value of other numeric inputs is at most 10^9.
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `float()` converts a numeric string into a number that may contain a decimal part. 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 `'S'` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Check `<=10`, then `<=50`.']
ANSWER
Solution
+
g = float(input())
if g <= 10:
print('S')
elif g <= 50:
print('M')
else:
print('L')