I FINALLY got the code to work, insofar as it returns the correct answer. However, the tutorial won't let me proceed. I get an error message along the lines of "Your function fails on digit_sum(xyz). It returns None when it should return SUM(x+y+z)" -- but the code DOES return that number!
Any ideas why this is happening? Do I need to change something in the code to have "None" not appear? Or do I need to write different code?.
my_list = () def digit_sum(n): n = str(n) my_list = (n) loops = len(n) n = int(n) # print how many digits have print loops # set number of digits to be the counter counter = loops # print the number being analyzed print my_list # set loop equal to number of digits total_numbers = 0 while counter > 0: ccc = int(my_list[counter-1]) # print out individual digits to check print ccc # sum the digits total_numbers = total_numbers + ccc counter -= 1 print "Total of individual digits is: " + \ str(total_numbers) print total_numbers digit_sum(434)