help please!
i keep getting this error message from my program:
Area = math.sqrt(( a + b + c )( a + b - c )( a - b + c )( b + c - a ))/4
TypeError: 'int' object is not callable

Sad
can someone please provide a fix?
i searched all over google and found nothing the helped

p.s. this is for CMPT 120... its due this Saturday and this is the only error left to fix in this stupid program... Sad
Callable?

Quote:
callable |ˈkôləbəl|
adjective
Finance: designating a bond that can be paid off earlier than the maturity date.
I really don't understand why that word would be in the error.
WhiteValkery wrote:
help please!
i keep getting this error message from my program:
Area = math.sqrt(( a + b + c )( a + b - c )( a - b + c )( b + c - a ))/4
TypeError: 'int' object is not callable

Sad
can someone please provide a fix?
i searched all over google and found nothing the helped

p.s. this is for CMPT 120... its due this Saturday and this is the only error left to fix in this stupid program... Sad


You need explicit multiplication. It thinks you are treating (a + b + c)(....) etc as a set of function calls.
In other words, in case you don't know what it means to have explicit multiplication, Python requires that you put in the multiplication operator (*) when you're multiplying:

Code:
( a + b + c )*( a + b - c )

Otherwise it's going to think you're trying to call a function, so if a=b=c=1 it will think you're trying to call the function

Code:
3(1)

Which you can't do, since it's an integer, not a function.
comicIDIOT wrote:
Callable?

Quote:
callable |ˈkôləbəl|
adjective
Finance: designating a bond that can be paid off earlier than the maturity date.
I really don't understand why that word would be in the error.
Callable as in it can't be called. Smile As Merthsoft and Elfprince said, implicit multiplication a la TI-BASIC is not allowed; Python sees it as an attempt to call a nonexistent function. Throw in some asterisks and he'll be all set.

Edit: Moved this to the general programming section, by the way.
oh my god... thank you soooo much!!!

i can't believe it was something to trivial!
thanks... now i finally finished this project!!!
WhiteValkery wrote:
oh my god... thank you soooo much!!!

i can't believe it was something to trivial!
thanks... now i finally finished this project!!!
Congrats, glad to hear it! Yeah, TI-BASIC teaches you bad habits in terms of implicit multiplication. C, C++, Java, Matlab, Python, and just about every computer scripting or programming language all disallow implicit multiplication.
KermMartian wrote:
WhiteValkery wrote:
oh my god... thank you soooo much!!!

i can't believe it was something to trivial!
thanks... now i finally finished this project!!!
Congrats, glad to hear it! Yeah, TI-BASIC teaches you bad habits in terms of implicit multiplication. C, C++, Java, Matlab, Python, and just about every computer scripting or programming language all disallow implicit multiplication.

This is particulary true of languages like Python where functions are first class citizens and can be passed around as arguments, so that something like f(x)(x)(x)(y) could potentially be a valid function call.

Code:
>>> def f(n):
...     if n%2:
...             return f
...     else:
...             return 3
...
>>> x = 3
>>> y = 2
>>> f(x)(x)(x)(x)(x)(y)
3
Heehee, I like Python constructs like that; they boggled my mind when I first saw them having never previously seen a similar structure in another programming language.
It's not particularly unusual, the same thing can be done in JavaScript:

Code:
var f = function(n) {
    if (n%2)
        return f;
    else
        return 3;
}
var x = 3, y = 2;
alert(f(x)(x)(x)(x)(x)(y));

Unfortunately, JavaScript also offers an ugly function f(n) { } syntax that somewhat conceals the fact that f is a variable.

Functional programming can offer some elegant ways to structure code, so it's nice that some of its features are being adopted in more "mainstream" languages. Smile
KermMartian wrote:
Heehee, I like Python constructs like that; they boggled my mind when I first saw them having never previously seen a similar structure in another programming language.


Psssh, even C has function pointers (though static typing makes it a bit less flexible). Python's real magic lies in things like generator expressions, comprehension syntax, (recursive) unpacking, slicing (with negative indexing), duck typing, in syntax + custom iterators, etc.
Hmm, I'll have to look into this more, although I'm not sure how it would be super-useful to me in everyday programming. Any tips?
The most useful things I've seen pointers to functions for have been:
1) In the game Wolfenstein3D, the guard AI is defined by a struct:

Code:
typedef struct statestruct
{
    boolean rotate;
    short   shapenum;           // a shapenum of -1 means get from ob->temp1
    short   tictime;
    void    (*think) (void *),(*action) (void *);
    struct  statestruct *next;
} statetype
You can see the void (*think)(void *), which is a function that defines the guard's movement AI, and action is how it shoots. This is very handy for FSMs that define behavior. Just pass in the function that it should call and you're good to go. Of course, in true OOP you can just override the base think and action methods; but it's good in C or ASM.
2) When writing a MIPS interpreter in MIPS, we had an array of functions (well, labels) that were indexed by opcode, so we could just branch opArr[opcode], basically

Code:
jumptable:    .word    ALU,blank,Jump,blank,BranchEqual,BranchNotEqual,blank,blank,AddImmediate,blank,blank,blank,blank
        .word    OrImmediate,blank,Lui,blank,blank,blank,blank,blank,blank,blank,blank,blank,blank
        .word    blank,blank,Mul,blank,blank,blank,LoadByte,blank,blank,LoadWord,LoadByteUnsigned,blank,blank,blank
        .word    blank,blank,blank,StoreWord,blank,blank,blank,blank,blank,blank,blank,blank,blank,blank
        .word    blank,blank,blank,blank,blank,blank,blank,blank,blank,blank
sysJumpTable:   
        .word    blank, printIntChar, blank, blank, printString, readInt, blank, blank, readString, blank
        .word    Terminate, printIntChar, readChar, blank, blank, blank, blank, blank
So, while not being exactly pointers to functions, it's the same concept. Jumptables are awesome.
That makes sense, thanks for that, Merth. Smile
KermMartian wrote:
Hmm, I'll have to look into this more, although I'm not sure how it would be super-useful to me in everyday programming. Any tips?


The big one is callbacks for events. Look at the disgusting mess Java has to put up with when dealing with UIs because of the lack of function pointers. Attributes in Python also resolve to functions that return a function that replaces the function that has the attribute, which is pretty awesome if a bit confusing.
Kllrnohj wrote:
Look at the disgusting mess Java has to put up with when dealing with UIs because of the lack of function pointers.

What? ActionListeners are bad?
Kllrnohj wrote:

Attributes in Python also resolve to functions that return a function that replaces the function that has the attribute, which is pretty awesome if a bit confusing.

This is, iirc, the ability to define custom getters and setters for data in new-style classes, right?
wow... these are some interesting stuff...

btw... why was this thread moved?
and why is it (moved back?)

i donno... can't tell if the "moved:" tag is just to show that the actual topic is moved or that its been moved here...
The topic was moved to the General Programming section is, where it is now, because I felt that that was the most appropriate place for it. And yes, you prompted an interesting discussion; nice job. Smile
KermMartian wrote:
The topic was moved to the General Programming section is, where it is now, because I felt that that was the most appropriate place for it. And yes, you prompted an interesting discussion; nice job. Smile

i see...

haha... i never intended it to be...
but yeah... thanks to you guys i was able to finish my project on time Smile

i was seriously baffled by that int object not callable error before...
i tried researching and found nothing... it took me so long just trying to figure that out that i pretty much gave up on that line and went working on some bonus stuff...

and then it turned out to be something so trivial...

thanks guys!
p.s. I LOVE THIS FORUM XD
WhiteValkery, we absolutely appreciate the enthusiasm, thanks! I hope that this topic will help other people with a similar problem who find it via Google. Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement