Build an Apply Discount Function - Build an Apply Discount Function

Tell us what’s happening:

In my code I have already defined the function but its saying the function is not defined, there is no typo in my function name

Your code so far

def apply_discount(price,discount):
    if type(price)!=int or type(price)!= float:
        return("The price should be a number")
    elif price<0:
        return("The price should be greater than 0")
    else:
        if discount<0 or discount>100:
            return("The discount should be between 0 and 100")
        else:
            final_price=price-(price*discount/100)
            return final_price
a=int(input('enter price:'))
b=int(input('enter discount:'))
apply_discount(a,b)




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.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 @goks,

This challenge is not meant to interact with a user. Instead, when you call the function, pass in the values literally as shown in the Tests. (see Test #7)

And to see what your function returns, wrap the function call in print().

Also, please review this theory lecture about how to use type() and isinstance():

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

I suggest going through the user stories again to make sure you have implemented them as asked.

Happy coding

Please help. I’ve created this script as suggested. All price and discount entries result correctly, but “Check the Code” says they don’t.

def apply_discount(price, discount):
    #3 Price not number
    if not isinstance(price, (int, float)):
        return 'The price should be a number'
    #4 Discount not number
    if not isinstance(discount, (int, float)):
        return 'The discount should be a number'
    #5 Price <=0
    if price <= 0:
        return 'The price should be greater than 0'
    #6 Discount range
    if discount < 0 or discount > 100:
        return 'The discount should be between 0 and 100'
    #7-8
    discount_amt = price * discount / 100
    final_price = price - discount_amt
    print(final_price)

apply_discount(100,20)

Thank you

Nicely done. Just finish off your function by returning final_price rather than printing it, and you’ve got it!

Thank you. Still getting used to when to use ‘print’ and ‘return’. As you suggested, I changed the ‘print()’ to ‘return’ and code tested successfully. One little lesson at a time. Thanks again.