Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

I am able to pass tests 1, 2 and 3, and although I used the same methodology (that i used for test 3) to answer test 4, it doesn’t work.

Your code so far

def apply_discount(price, discount):
    if type(price) is not int or type(price) is not float:
        return 'The price should be a number'

    if type(discount) is not int or type(discount) is not float:
        return 'The discount should be a number'
    
    if price <= 0:
        return 'The price should be greater than 0'
    
    if discount < 0 or discount > 100:
        return 'The discount should be between 0 and 100'

    return discount/price * 100

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build a Discount Calculator - Build a Discount Calculator

are you sure this is how calculate the total price after discount?

Thanks for the help, for now I’m going through the problems one by one. Do you know why test 4 isn’t passing even though it’s using the same methodology as test 3?

(Test 3 being 3. When apply_discount is called with a price (first argument) that is not a number (int or float) it should return The price should be a number.)

(Test 4 being 4. When apply_discount is called with a discount (second argument) that is not a number (int or float) it should return The discount should be a number.)

the two conditions have the same issue actually

consider, when price is a float, type(price) is not int is True tho, so the whole condition is True and the function returns 'The price should be a number'

1 Like

Thank you so much, that was it. Can’t believe I was stuck for so long

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.