Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

My 4th line for checking if discount is a int or float is not working. I did the same thing for price and it worked. Does anyone know why?

Your code so far

def apply_discount(price, discount):
    if price != int or float:
        return 'The price should be a number'
    if discount != int or 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 price should be greater than 0'
    return price - (price % discount)

Your browser information:

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

Challenge Information:

Build a Discount Calculator - Build a Discount Calculator

1 Like

Neither of those if statements is doing what you expect.

You have two conditions here: 1) price != int, and 2) float. The or operator separates your conditions.

How can you change your second condition to get the correct result?

are you sure this is checking if price is of type int or float?

I tried using not float but it still didn’t work

If you just write “not float” for the second condition, how are you checking that price is not float?

https://www.freecodecamp.org/learn/python-v9/lecture-understanding-variables-and-data-types/what-are-common-data-types-in-python-and-how-do-you-get-the-type-of-a-variable

Read about isinstance() at the end of this link