Digit_sum challenge


#1



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


I am trying to complete exercise by using floor division , but honestly i don't really get how it works .


number=[]

def digit_sum(n):
    while n>0 :
        number.append(n%10)
        n = n // 10 
    print number
    
        while len(number)>1:
            number.append((sum(int(number[0]), int(number[1]))))
        print number


#2

the first bit:

def digit_sum(n):
    while n>0 :
        number.append(n%10)
        n = n // 10 
    print number

is pretty good. But you should declare a variable total and give it a value of zero, then add n%10 to total rather then appending to list


#3

Ok, got it. Thanks! Passed the validator.


#4

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