Drill

ProblemsPython › pricing

Discount, but never below the floor

easypricingPython

Sales can discount freely, except that a contract sets a price the item may never go under.

discount_with_floor(price: int, percent: int, floor_price: int) → int

Solve it in the editor →

Where you start

def discount_with_floor(price: int, percent: int, floor_price: int) -> int:
    

Worked examples

CallResult
discount_with_floor(1000, 20, 500)800
discount_with_floor(1000, 70, 500)500
discount_with_floor(1000, 20, 1200)1200
discount_with_floor(1000, 0, 500)1000

Hint

Two steps, in order: discount, then clamp.

Reference solution in Python
def discount_with_floor(price: int, percent: int, floor_price: int) -> int:
    cut = price if percent < 1 or percent > 100 else price - price * percent // 100
    return max(cut, floor_price)

The same problem in another language

More pricing problems in Python