My code:
def digit_sum(n):
result = 0
s = str(n)
for c in s:
result += (int)c # invalid syntax??????????
return result
print digit_sum(1234)
Result:
result += (int)c # invalid syntax??????????
^
SyntaxError: invalid syntax
The function is supposed to return the sum of each digit of the argument "n".
Why do I get SyntaxError
in the commented line? The variable c
is of type str
ing so it shouldn´t be an issue to apply a type cast to int
.