Digit_sum


#1



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


the error was that it was going in an infinte loop


instead of adding the digits of the number


def digit_sum(n):
    result=0
    i=0
    j=n
    while(j):
        
        i=j%10
        result+=i
        j=int(n/10)
    return result

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


#2

n is never changing value so while (j) will never be False. Did you mean to write,

j = int(j / 10)

?


#3

ohhh...im so stupid!!
thanks Roy


#4

It's a simple and innocent error that anybody could make. You are not stupid, so shake it off, and dig right back in. Add this one to your debugging check list: check variables.


#5

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