Digit_sum


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
PRACTICE MAKES PERFECT
digit_sum

<In what way does your code behave incorrectly? Include ALL error messages.>
What’s wrong with my code?

<What do you expect to happen instead?>

```python

Replace this line with your code.

def digit_sum(n):
  total = 0
  while n != 0:
    num = int(n%10)
    n = n//10
    total = total + num
  return total

print digit_sum(1234)
<do not remove the three backticks above>

#2

nothing seems wrong, i reset the exercise, ran your code, and i get a pass

what error message do you get? Maybe you can show a screenshot?


#3

This is the error I’m getting. And I’ve indented the return to be inside the function but I’m getting the same error


#4

that is weird, because the function is defined, if i run your code here:

https://repl.it/repls/DopeyAdoredCavy

it works fine. Maybe refresh the page


#5

After the refresh I’m getting these two errors


#6

May be it is indentation problem.?


#7

It might be, but I don’t seem to find it. If you have any ideas , I definitely need one. I’ve ran out of ideas.


#8

given it gives an indention error, this is indeed a very viable option

the editor under certain corner cases makes it really difficult to spot an indent issue

the indent issue seems to be on line 7, merge line 6 and 7, then separate them and re-indent line 7


#9

Many thanks. It worked :smile:


#10

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