Python Forum
[split] [split] New to the forum, how to post a question?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] [split] New to the forum, how to post a question?
#1
Please find my code , I am getting below error

class it : def rec (self,c,id,ac,bd,ad,bc): return (c + id)(ac - bd) + (ad + bc) a = it() a.rec(45,56,67,89,89,45)
I am getting error as type error : "int object is not callable "
please help me
buran write Feb-12-2022, 11:07 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
you need an operator between (c + id)(ac - bd)
thus:
class it : def rec (self,c,id,ac,bd,ad,bc): return (c + id)*(ac - bd) + (ad + bc) a = it() a.rec(45,56,67,89,89,45)
BashBedlam and karnik like this post
Reply
#3
Python is having a difficult time parsing this:
(c + id)(ac - bd)
Parenthesis can be used to group operations, used to create tuples, used to call a function, used to call a method.

Python can tell "(c + id)" is not a tuple, because tuples need commas. It is also not a function or method call because there is nothing before the parenthesis. It must be an operation surrounded by grouping parenthesis. The result of the addition is 101. So now Python is looking at this:
101(ac - bd)
This looks like a function call, but 101 is an int, not a function, so Python raises an error.

It may seem silly that python thinks "(c+id)(ac - bd)" is a function call. How can the result of an operation "(c + id)" be a function? Actually, this kind of thing happens all the time in Python. In this example a dictionary lookup returns a function. Python cannot know this when it is parsing the code. It has to rely on "object()" is a function call, so lets see if "object" is callable. In this example the object is a function, so it is callable. In you example the object was an int which is not callable.
import operator operators = {"+":operator.add, "-":operator.sub, "*":operator.mul, "/":operator.floordiv} def solve(equation): a, op, b = equation.split(" ") return operators.get(op)(int(a), int(b)) print(solve("5 + 4"))
Output:
9
karnik and ndc85430 like this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] re.split issue paul18fr 10 938 Nov-14-2025, 06:02 PM
Last Post: deanhystad
  [split] print two different sequence number Reema 1 632 Nov-10-2025, 05:37 AM
Last Post: Gribouillis
  [split] How to continue code after .show() in matplotlib? pythonnewbie62 1 815 Apr-28-2025, 04:02 PM
Last Post: deanhystad
  [split] ibm_db install problem SQLPython 1 2,284 Feb-13-2025, 07:24 PM
Last Post: buran
  [split] Newbie needs help Schoe1 0 806 Feb-12-2025, 06:57 PM
Last Post: Schoe1
Star how to split pdf under 10mb using python skchui9786 4 2,860 Jan-18-2025, 03:25 AM
Last Post: skchui9786
  [split] another problem with code blakeusherremix68 0 865 Dec-23-2024, 11:36 PM
Last Post: blakeusherremix68
  [split] Code help emma1423 1 1,111 Dec-13-2024, 02:00 PM
Last Post: perfringo
  [split] Prime numbers saima 1 1,003 Dec-09-2024, 02:19 AM
Last Post: jefsummers
Question [split] How to ask Smart Questions (thread title expansion) darkuser 4 2,238 Nov-11-2024, 01:27 PM
Last Post: deanhystad

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.