To all

I am having some trouble with the python lesson: **Practice Makes Perfect- exercise 4**. I created a code which I was looking to define as digit_sum. This code should allow me to take a positive integer n as input and return the sum of all that number’s digits. For example, digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4. My code, when implemented in IDLE undefined (see **version 1**), works fine and achieves the objective. However when formatted as a user-defined function in (see **version 2**), I am unable to achieve the same results I know there are easier ways to achieve the objectives by completely re-writing my function but I was hoping to understand why the second version was not able to run as expected and what I am lacking in my understanding of the capabilities of user-defined function.

**version 1**

```
n=434
number = []
while n>0:
if n %10 != 0 and n>10:
number.insert(0,n%10)
n = int((n - n%10)/10)
print(number)
elif n <= 10 and n - int(n) == 0:
number.insert(0,n)
print(number)
n=sum(number)
break
print (n )
```

**version 2**

many thanks in advance