Build an apply discount function

Tell us what’s happening: i write the code, that i believe should be correct, but it doesnt work. the price one where if the price isnt a number it returns a string is correct , but the one with discount which is almost identical is somehow wrong . Dont pay attention to the user stories 7 and 8 of this , i diditn write themm yet

Your code so far

def apply_discount(price, discount):
    if price != (int or float):
        return 'The price should be a number'
    elif discount != (int or float):
        return 'The discount should be a number'
    elif price <= 0:
        return 'The price should be greater than 0'
    elif discount < 0 or discount > 100:
        return 'The discount should be between 0 and 100'
    

Lesson URL https://www.freecodecamp.org/learn/python-v9/lab-discount-calculator/build-a-discount-calculator

Hi @matanskis.l,

Please review this theory lecture about how to check the type of a variable, especially the last example, which shows how to check a variable against more than one type:

Understanding Variables and Data Types - How Do the type() and isinstance() Functions Work? | Learn | freeCodeCamp.org

Happy coding

i still dont get it, as even when i try to check what type of variable the price or discount is it says that they are not defined, so i cant do anything…

Please post your updated code for more help.

wait, i think i might have understood it i have to say isinstance(price, (int, float)) == False: instead of saying !=, right?

Yes. You can also use not to negate the expression rather than == False.

ok, but how do i complete the 7 and 8 user stories? @dhess

this is my code so far

def apply_discount(price, discount):

    

    if isinstance(price, (int, float)) == False:

        return 'The price should be a number'

    elif isinstance(discount, (int, float)) == False:

        return 'The discount should be a number'

    elif price <=0:

        return 'The price should be greater than 0'

    elif discount < 0 or discount >100:

        return 'The discount should be between 0 and 100'

    

apply_discount(100,20)

print(apply_discount(100,20))

because i know that the fact that it prints none is because i dont have return under the function, ill add return price - discount

heres a slighty upadted code

def apply_discount(price, discount):

    

    if isinstance(price, (int, float)) == False:

        return 'The price should be a number'

    elif isinstance(discount, (int, float)) == False:

        return 'The discount should be a number'

    elif price <=0:

        return 'The price should be greater than 0'

    elif discount < 0 or discount >100:

        return 'The discount should be between 0 and 100'

    elif isinstance(price and discount, (int, float))==True:

        return price - discount

        

apply_discount(100,20)

print(apply_discount(100,20))

you do not need an additional condition here, but I would double check how to calculate the discount, remember that the discount is a percentage, not a discount in dollars