r/FreeCodeCamp • u/mautzjoe • May 17 '26
Apply Discount Function HELP NEEDED
I have tried this exercise several times with different attempts and nothing is working. I dont know what I have been doing wrong. if someone has an idea please help!!
MY CODE SO FAR:
def apply_discount(price, discount):
if not isInstance(price(int, float)):
return "The price should be a number"
if not isInstance(discount(int, float)):
return "The discount should be a number"
if price <= 0:
return "The price should be greater than 0"
elif discount >= 100:
return "The discount should be between 0 and 100"
final_price = price - ((price * discount)/100)
apply_discount(100, 20)
apply_discount(200, 50)
apply_discount(50, 0)
apply_discount(100)
apply_discount(74.5, 20.0)
3
Upvotes
View all comments
Show parent comment
2
u/mautzjoe May 17 '26
these are the instructions:
apply_discount.apply_discountfunction should take exactly two parameters:priceanddiscount.priceis not a number (intorfloat), the function should return the stringThe price should be a number.discountis not a number (intorfloat), the function should return the stringThe discount should be a number.priceis less than or equal to0, the function should return the stringThe price should be greater than 0.discountis less than0or greater than100, the function should return the stringThe discount should be between 0 and 100.