Build an Apply Discount Function - Build an Apply Discount Function

Tell us what’s happening:

My code keeps saying ‘int’ object is not callable when I run it. How to fix this?

Your code so far

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

apply_discount(7, 4)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36

Challenge Information:

Build an Apply Discount Function - Build an Apply Discount Function

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-discount-calculator/695774002591bbc5f8cf3e53.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @orsenrb,

Are you missing something? isinstance takes two arguments:

Understanding Variables and Data Types - How Do the type() and isinstance() Functions Work? | Learn | freeCodeCamp.org

Please wrap your function call(s) in print() so you can see what your function returns in the console.

Tiip: Using print() inside your code is also a good way to “see” what your code is generating when something isn’t working as expected.

Happy coding

def apply_discount(price, discount):

if not isinstance(price ,int or float):

return ‘The price should be a number’

elif isinstance(price, int or float):

if price == 0:

return ‘The price should be greater than 0’

else:

return price % discount

if not isinstance(discount, int or float):

return ‘The discount should be a number’

elif isinstance (discount, int or float):

if discount < 0 or discount > 100:

return ‘The discount should be between 0 and 100’

else:

return price % discount

print (apply_discount(4, ‘s’))

It doesn’t return ‘discount should be a number’.

Please review this theory lecture for the correct syntax to use with isinstance when you’re checking a variable against multiple types.

Also, please format your code as follows when you post it –


There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:

Happy coding