4/15 digit_sum


#1

what’s wrong in this code

def digit_sum(n):
  a=0
  while n:
    b=n%10
    a+=b
    n=n/10
    if n==0:
      print a
      break

i got output as 11.

Error:Your function fails on digit_sum(434). It returns None when it should return 11.


#2

you never return the sum of the digits?


#4

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