Digit_sum tried to be brave and do the challenge


#1

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/digitsum?action=lesson_resume

This is what I came up with and it seems to give a correct result (in this case15) but codeacademy is not happy with it :slight_smile:
Can anybody give me some pointers?
Thanks a lot in advance.



def digit_sum(n):
  count=0
  while n>0:
    x=n%10
    count=count+x
    n=n//10
  else:
    print count
digit_sum(375)



15. Practice Makes Perfect
6. is_prime
#2

it seems you completely tackled the challenge, but then forgot to return count:

# count is only printed here, not returned
print count

and then print the returned result at function call by adding a print statement in front of the function call:

print digit_sum(375)

nicely done go for the difficult approach and completely solve it yourself :slight_smile:


#3

yayyy me :blush:, thanks for the help! Much appreciated.


#4