Loyalty points for a basket
The card scheme awards one point for every full ten lira spent, and doubles that on promotion days.
- The amount arrives in kuruş, so ten lira is 1000.
- Part of a ten does not earn anything.
- A negative amount is a refund and earns nothing.
points_for(spend: int, double_day: bool) → int
Where you start
def points_for(spend: int, double_day: bool) -> int:
Worked examples
| Call | Result |
|---|---|
points_for(10000, False) | 10 |
points_for(10999, False) | 10 |
points_for(10000, True) | 20 |
points_for(999, False) | 0 |
Hint
Integer-divide by 1000, then double if the flag is set.
Reference solution in Python
def points_for(spend: int, double_day: bool) -> int:
if spend <= 0:
return 0
base = spend // 1000
return base * 2 if double_day else base