4/15 digit_sum


#1



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


Every input into digit_sum(n) prints 3


Replace this line with your code. 
def digit_sum(n):
    digit = len(str(n))
    total = 0
    for i in range(digit):
        total = total + int(str(i))
    return total

print digit_sum(123)


#2

try using an if/while/else statement instead of a loop


#3

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

print digit_sum(1)

got it


#4

Good job :grin: :grinning:


#5

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