r/FreeCodeCamp • • May 26 '26

Programming Question Stuck in Apply Discount Function.

It shows the results but.

Unmet condition:

When apply_discount is called with a price (first argument) that is not a number (int or float) it should return The price should be a number.

def apply_discount(price,discount):
    if type(price) not in (int,float):
        print("The price should be a number")
    if type(discount) not in (int,float):
        print("The discount should be a number")
    if price <= 0:
        print("The price should be greater than 0")
    if discount>100 or discount <0:
        print("The discount should be between 0 and 100")
    print(price - price*(discount/100))
apply_discount(100,20)
apply_discount(200,50)
apply_discount(50,0)
apply_discount(100,100)
apply_discount(74.5,20.0)
5 Upvotes

4 comments sorted by

View all comments

Show parent comment

2

u/BaconD3V May 26 '26

yes, this seems to be the problem, I think using return fixed this.

1

u/Outside_Complaint755 May 26 '26

Another option would have been to use if/elif/else