Help needed for 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.>
https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/digitsum?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
File “python”, line 5
SyntaxError: can’t assign to operator

<What do you expect to happen instead?>

```python

def digit_sum(n):
str(n)
for i in n:
int(i)
i+i = n
return n

<do not remove the three backticks above>

#2

Look at here

str(n)

you changed the integer to a string.but when you loop through n it’s still integer as you didn’t store the changing value to n.
same for the following line too

int(i)

and here

i+i = n

you can’t assign a value to a variable like this.The value should be at right-hand side of the = sign

variable = value

and don’t use n for assigning instead create a new variable then do the additions.


#3

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