Why Do I Keep Getting: 'int' Object Is Not Callable In Python?
x = 4 y = 5 a = 3(x + y) print(a) I keep trying to solve that. I've even tried this. x = input('Enter value for x:') Enter value for x:4 y = input('Enter value for y:') Enter
Solution 1:
I suspect that you want 3(x + y)
to be acted upon as that would be in algebra, that is to multiply the result of x + y
by 3. For that you need to use the multiplication operator *
:
a = 3 * (x + y)
Python will take the parentheses after a token as a function call as per f(x + y)
, and since 3
is not a function, you are told it is not "callable" (meaning a function, or something you can treat as a function).
Solution 2:
To multiply, you need to use the *
operator:
a = 3 * (x + y)
3(x + y)
looks and feels like a function call for the function 3
, which is why you're getting the error.
FWIW, algebraic expressions where you simply abut two symbols next to each other does not translate directly in most programming languages, unless they were specifically designed for mathematics.
Post a Comment for "Why Do I Keep Getting: 'int' Object Is Not Callable In Python?"