Code doesnt work


#1
def digit_sum(x):
  x = str(x)
  total = 0
  for s in x:
    integers = int(s)
    total = total + integers
  print total

this function does what its supposed to…it takes a number and sums up the digits…but i still cant pass the exercise


#2

what error message do you get? Maybe there is clue there why the code isn’t working


#3

it says it should return 11 but returns none…but actually it returns 11


#4

no, your function prints 11, that is quite a difference. Function return None by default, so that is a big hint


#5

yeah i figured it out just now…used return and now it works


#6

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