Digit_sum


#1

Hi Team,
For this digit_sum task I have written below code and which giving me correct ouput but not sure why in codecademy console at bottom a message is coming and the course is not progressing.The NEXT button is in disabled state.

“Did you create a function called digit_sum? Your code threw a “global name ‘digit_sum’ is not defined” error.”

My code


def digit_sum(n):
  num_string = str(n)
  #list_a = [num_string]
  list_b = []
  for i in range(0,len(num_string),1):
    x=[num_string[i:i+1]]
    list_b = list_b + x
    print list_b
  Total = 0
  pos = 0
  l = len(list_b)
  
  while (pos < l):
    Total = Total + int(list_b[pos])
    pos += 1
  print "Total addition: ",Total
  
value= int(raw_input(">: "))
print value
digit_sum(value)

#2

the function needs to return the sum of the digits, read the instructions carefully


#3

I have added return Total but still same error message and this time the console not responding while I am entering the input value.


#4

I am suppose to guess how you implemented the return statement? Please show me

exercise link, for my self so i can quickly access the exercise


#5

Thank you stetim94 for the suggestion. Program is working fine now. I have re-lunched my browser and tried again the code ,now its working fine.


#6