Drill

ProblemsPython › pricing

Loyalty points for a basket

easypricingPython

The card scheme awards one point for every full ten lira spent, and doubles that on promotion days.

points_for(spend: int, double_day: bool) → int

Solve it in the editor →

Where you start

def points_for(spend: int, double_day: bool) -> int:
    

Worked examples

CallResult
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

The same problem in another language

More pricing problems in Python