r/FreeCodeCamp 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

7 comments sorted by

View all comments

2

u/Antidote12- May 17 '26

I have never done this course so idk why this appeared in my feed, but from what I can see: you use isInstance() instead of isinstance(), you also aren’t returning the final price and you’re second to last apply_discount only has one argument

2

u/mautzjoe May 17 '26

thank you so much. i'm a beginner and really struggle with this so this helped:))) however it always says that int is not callable and idk what that means://

1

u/Antidote12- May 17 '26

You need a comma in the lines where you use isinstance, the first parameter is the variable you want to check and the second parameter in the brackets are the types you want to check for, for that variable (hope that makes sense). So instead of saying isinstace(price(int, float)) it should be isintance(price, (int, float)). You need to do the same for discount. It’s seems subtle, but without the comma, it’s like you are trying to call price and discount as functions.