def digit_sum(n): result = 0 str_position = len(str(n)) str_value = str(n) #Missing code to identify x for x in str_position: result = result + int(x) str_position += 1 return result print digit_sum(1234)
Hello all, phew this has been a very difficult chapter. I’ve been doing and redoing this section several times to make sure I understand it (and I plan to do it once more after I complete all of the tutorial as this is great practice). I’m stuck though.
My best guess with what is currently wrong is that there’s nothing to identify the variable “x”. That is to say there’s nothing tying it to the “n” variable. I wanted to do something along the lines of result = result + int(str(n)) but that didn’t work out.