Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

When I run the test, it says my code is incorrect
So This is my code thus far and I have checked the function for every possible combination of inputs and it works perfectly but when I hit the run the tests button, it says the code is wrong from step 3 onwards. Step 3 is when apply_discount is called with price that is not a number it should return the price should be a number which my code does. Any help would be appreciated. Thanks!

Your code so far


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

apply_discount(100, 20)
apply_discount(200, 50)
apply_discount(50, 0)
apply_discount(100, 100)
apply_discount(74.5, 20.0)




Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0

Challenge Information:

Build a Discount Calculator - Build a Discount Calculator

what do you think is returned when you do this?

The statement inside the print function ‘The price should be a number’

are you sure?

test it out

print("The function returns", apply_discount(100, 20))

haha wow you are right. i guess returning the print from inside the function was a mistake. so if i am understanding this i should just return the strings and values from inside the function and then call the function by using print(apply_discount(100, 20))? i tried it and it worked but i don’t really understand why though? why was i returning none when i returned print from inside the function?

because you are returning print, and the value returned by print is None

test it:

print("Print returns...", print())

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