<In what way does your code behave incorrectly? Include ALL error messages.>
Oops, try again. Your function fails on digit_sum(434). It returns 4 when it should return 11.

It should keep running the code with the other numbers


def digit_sum(n):
num_str = str(n)
index = 0
for i in range(len(num_str)):
total = 0
total = total + int(num_str[i])
return total

<do not remove the three backticks above>


If anyone can help it would be much appreciated!


Be sure to initialize before the loop.


Thanks for the advice!


Also, this unused variable definition can be safely removed.


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