Digit sum


#1

This is my code:

def digit_sum(n):
  total = 0
  str(n)
  for number in n:
    int(number)
    total += number
  return total

I tried hard to fix it but I couldn’t. This is my error message:

Does your digit_sum function take exactly one argument (a positive integer)? Your code threw a “unsupported operand type(s) for +=: ‘int’ and ‘str’” error.

Can someone please help me?
Thanks


Digit Sum
#2

here:

str(n)

you convert n to string, but don’t store the string anywhere?

same logic applies here:

int(number)

you convert back to integer, which is good, but again, not storing the integer anywhere.


#3

okay I got it thanks!


#4