Store Discount System
Programming Basics · Python
TASK
Problem
Given purchase `amount`: 0% below 1000, 5% from 1000 to below 5000, 10% from 5000 upward. Print final price.
EXAMPLE
Example
6000
5400.0
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. The `*` operator multiplies 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 `a` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Check the higher threshold first.']
ANSWER
Solution
+
a = float(input())
if a >= 5000:
a *= 0.9
elif a >= 1000:
a *= 0.95
print(a)