"str object is not callable" please help


Hello evryone i'm stuck please help :slight_smile:

I get "Your function crashed on 434 as input because your function throws a "'str' object is not callable" as an error i read about someone having the same error (not on code academy) about redifinning what str ment so i assume the error is when i convert n from int to a string.

Replace this line with your code. 
def digit_sum(n):
     if n > 0:
         n = str(n)
         n (int, n)
         return sum(n)
        print "Your number is not positive sorry"

Thanks in advance,


This is the problem. I am not sure what you are trying to do in that line, so I can't really suggest anything better.


Hello :smile:
Was trying to get the average of n I think. (forgot about the sum command) `

def digit_sum(n):
    n = str(n)
    n = int(n)
    return n

However i'm still getting errors. ". Does your digit_sum function take exactly one argument (a positive integer)? Your code threw a "unsupported operand type(s) for +: 'int' and 'str'" error." Do you know where this could come from? Thanks a lot for helping btw.


Here you turn the string n into a list of strings with length one.

You can't sum a list of strings, that only works with numbers. Also you need to store the sum somewhere, e.g. total = sum(integer_list).

You can't turn list into integers, you need to turn all the strings in the list to into integers.


A string is iterable. We can build a list of integers directly from that.

def digit_sum(n):
    return sum([int(x) for x in str(n)])


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.