Digit_Sum Nightmare


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096#


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
        str(n)    
        sum_of_numbers += int(n)
    return sum_of_numbers


#2

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.


#3

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