Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

I’m trying to figure out why my code isn’t passing the 4th test because I wrote if the discount variable is not an integer or a float in multiple different ways and it doesn’t want to complete the test can anyone tell me please what I’m doing wrong?

Your code so far

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

Your browser information:

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

Challenge Information:

Build a Discount Calculator - Build a Discount Calculator

are you sure that is the correct method to check the datatype of a variable? you may want to review the lesson where data types are introduced https://www.freecodecamp.org/learn/python-v9/lecture-understanding-variables-and-data-types/how-do-you-declare-variables-and-what-are-naming-conventions-to-name-variables

I’ve tried:

 if discount is not int or float:
     return 'The discount should be a number'

I’ve also tried what’s written in the initial post

I’ve tried separating it into 2 separate lines and none of these methods have worked

that is not the way, you should really review the lesson

this one, I linked to the wrong one: 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

I tried the isinstance function and it still didn’t work

unless I’m still doing it wrong

post your code so we can check

here is my current code:

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

This isn’t how or works. On each side of or there needs to be a complete expression. I’ll put brackets to make it more clear what you’re checking

    if (price is not int) or (float):

If price is not an int, then it will be true.

float by itself is a class, so it will always be true

print(bool(float))
>> True

so I updated my code here it is:

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

is this updated code better use of an or statement?

Test it, does it work the way that you expect?

for the 3rd test it still passes but the 4th test is still failing

Which is the correct way to check for an int?

You need to do micro tests of each part of code.

Micro tests:

price = 5
print(price is not int)
price = 5.1
print(price is not int)

>> True
>> True

I’ll try these micro tests and see if they work

Which is the correct way to check for an int?

Yes, this is better to answer that question. You can’t test it though because it’s not the correct way to check for an int

ok its been a good while since I last wrote an integer check so maybe that’s why I can’t get the 4th test to complete

You seem to have a few in this same block of code?