Build an Apply Discount Function - Build an Apply Discount Function

Tell us what’s happening:

I think that I met all the criteria yet I cannot seem to pass no. 3, no.4. Does it have something to do with me using “else” as the means of saying “The price should be a number”?

Your code so far



def apply_discount(price, discount):
    if not isinstance(price, (str, bool)):
        if price <= 0:
            return('The price should be greater than 0')
    else:
        return("The price should be a number")
    if not isinstance(discount, (str, bool)):
        if discount < 0 or discount > 100:
            return('The discount should be between 0 and 100')
    else:
        return("The discount should be a number")

    if price and (discount < 100) >= 0:
            add = price - price * discount/100
            return add



print(apply_discount("one", 49))



Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Build an Apply Discount Function - Build an Apply Discount Function

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-discount-calculator/695774002591bbc5f8cf3e53.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @limejam,

If price is not a number (int or float), the function should return the string The price should be a number

Why are you checking for str or bool types when the instruction clearly says you should check for int or float types?

Check your logic. A return stops code processing, so you don’t need to use else.

Happy coding