Build an Apply Discount Function - Build an Apply Discount Function

Tell us what’s happening:

please help, After reading the instructions I separated the condition check to determine the return, but it was still wrong.

You should define a function named apply_discount.

  1. The apply_discount function should take exactly two parameters: price and discount.

  2. If price is not a number (int or float), the function should return the string The price should be a number.

  3. If discount is not a number (int or float), the function should return the string The discount should be a number.

Your code so far

def apply_discount(price, discount):
    
    if type(price) != 'int' or type(price) != 'float':
        return 'The price should be a number'
    elif type(discount) != 'int' or type(discount) != 'float':
        return 'The discount should be a number'
    # elif price <= 0:
    #     return 'The price should be greater than 0'
    # elif discount < 0 or discount > 100:
    #     return 'The discount should be between 0 and 100'

a = 'test'
b = 'test'
apply_discount(a, b)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Build an Apply Discount Function - Build an Apply Discount Function

Hey @nokyardiyansyah,

When doing a type check in Python, you compare it directly to the int and float data types, not to a string containing them.

I hope that helps, and happy coding!

i try like this not working

def apply_discount(price, discount):

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

        return 'The price should be a number'

It’s best to surround your code with three backticks ` above and below the code. Note that these are not a single quotes: '. I edited your code for readability. Like this:

```
my code here
```

Now, you must check your logic in this and think about how isinstance works. isinstance returns whether or not something is the type you pass into it. So, what you’re saying right now is (in more plain English):

If price is an int or price is a float
then return ‘The price should be a number’

Think about how you can use True and False in Python to get the response you want.