Digit_Sum Nightmare



Hey guys, I am very lost in this problem, mainly overwhelmed by the task. I have attempted it but I know for sure it doesn't work. I am trying to convert the numbers to string, would I require a list of sorts? or will the string itself behave like a list when i call it in the for statement?

Please Help as I just need to know how to approach this problem.

def digit_sum(n):
    for num in n: #for each number in n, convert it to string
        sum_of_numbers == 0
        sum_of_numbers += int(n)
    return sum_of_numbers


A number is not iterable. We need to cast it as a string so we can iterate over it.

This line is not a statement, but an expression. It needs to be assigned to a variable before the loop.


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