Drill

ProblemsPython › pricing

Apply a promo percentage

easypricingPython

The till applies a promo code to a price held in minor units — kuruş, cents, whatever the currency splits into.

discounted_price(price: int, percent: int) → int

Solve it in the editor →

Where you start

def discounted_price(price: int, percent: int) -> int:
    

Worked examples

CallResult
discounted_price(1000, 20)800
discounted_price(999, 10)900
discounted_price(1000, 0)1000
discounted_price(1000, 150)1000

Hint

Reject the bad range first, then integer-divide.

Reference solution in Python
def discounted_price(price: int, percent: int) -> int:
    if percent < 1 or percent > 100:
        return price
    return price - price * percent // 100

The same problem in another language

More pricing problems in Python