So, I'm trying to use a for loop to increment a variable I created called
sum with the last digit of the input, then dividing the input by 10 until there's only one digit, then adding it to
Here's my code:
def digit_sum(n): sum = 0 for len(n) > 1: num = n - int(n/10)*10 sum += num n = int(n/10) return sum
However, it always gives me the following mistake:
File "python", line 3 for len(n) > 1: ^ SyntaxError: invalid syntax
What's wrong with my code?