Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

I’m not sure why my statements aren’t passing the tests, am I not supposed to use isinstance?

Your code so far

def apply_discount(price, discount):
    if not isinstance(price, (int, float)):
        return print('The price should be a number')
    if not isinstance(discount, (int, float)):
        return print('The discount should be a number')
    if price <= 0:
        return print('The price should be greater than 0')
    if discount < 0 or discount > 100:
        return print('The discount should be between 0 and 100')
    new_price = price * ((100-discount)/100)
    return print(new_price)

apply_discount(100, 20)


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.2 Safari/605.1.15

Challenge Information:

Build a Discount Calculator - Build a Discount Calculator

Why don’t you print your function call so you can see the results of the function yourself?

Don’t rely on the tests to debug your program

1 Like

What do you see in the console when you test your code like this?

print(apply_discount(100, 20))

ohhh okok I got it ty

I am having trouble with steps 7 - 11

Here is my code:

def apply_discount(price, discount):

if not isinstance(price,(int,float)):

    return('The price should be a number')

elif price <=0:

    return('The price should be greater than 0')

elif not isinstance(discount, (int,float)):

    return('The discount should be a number')

elif (discount < 0 or discount >100):

    return('The discount should be between 0 and 100')

print(price*(1-discount/100))

print(apply_discount(100,20))

apply_discount(200,50)

apply_discount(50,0)

apply_discount(5,100)

apply_discount(74.5,20)

Please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.

Thank you.