4/15 int object is not callable


#1

def digital_sum(x) :
tot = 0
for i in str(x) :
tot = tot + int(i)
return tot

print digital_sum(434)

I have the good result with python windows and my code give the good answer but code academy said
"Your fonction fail on 434 enter because int object is not callable"

Thanks for your help


#2

Hi @mbunel ,

The function that you posted is named digital_sum, but the instructions asked for one named digit_sum. So, this message that you posted must apply to an earlier version of your code ...

"Your fonction fail on 434 enter because int object is not callable"

The code that you posted is not formatted properly, so we cannot see its indentation. But, if you change the function's name to digit_sum, as follows, in the function header and in the statement that calls it, it should work ...

def digit_sum(x):
    tot = 0
    for i in str(x) :
        tot = tot + int(i)
    return tot

print digit_sum(434)

#3

Hi geomaticmashups,

I have write exactly the same code as you but code academy still give me the same answer.
"Your fonction fail on 434 because int object is not callable"
I test my fonction with different number an it works even for 434.


#4

Hi @mbunel ,

I have just tested the following code again, and it does pass:

def digit_sum(x):
    tot = 0
    for i in str(x) :
        tot = tot + int(i)
    return tot

print digit_sum(434)

Make sure that your function has the correct name, and check the other details carefully, including indentation.


#5

that error is due to your indentation of "return tot"
make sure the return closes the for loop instead of being part of it


#6

thanks geomatic...it help me..:grin:


#7

i tried it and it doesn't work


#8

9 posts were split to a new topic: I've absolutely no idea about 4/15 & 5/15