Digit_sum


#1



def digit_sum(n):
    m = str(n)
    i=0
    w =0
    while i < len(m):
        k=m[i]
        w +=int(k)
        i+=1
        if i == len(m):
            print w
digit_sum(1234567)   

Please help ! I tried this code. But I am getting an error.

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


#2

from the instructions:
For example: digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4

see the word return in that line? It indicates you need to use the return keyword, return w instead of printing it


#3

The rest of the code is fine


#4

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