4/15 digit_sum - why does my code not work?


#1
def digit_sum(n):
  a = abs(n)
  b = str(a)
  c = []
  for char in b:
    c.append(int(char))
  return sum ( c )

#2

Doesn’t work, or doesn’t pass?


#3

forgive me if that’s a stupid question, but what’s the difference?


#4

doesn’t work means the code does not produce the correct digit sum, doesn’t pass means its not passing the exercise despite producing correct digit sum


#5

well, actually, it returns only the absolute of the first digit in the number.


#6

what does absolute have to do with it? I ran your code, and it worked fine


#7

I have no idea, why, but thank you for editing my post - it turned out my indentation was wrong. Thank you for your help and sorry for my unperspicacity.


#8

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