su=0

d=[]

def digit_sum(n):

n=str(n)

for x in n:

x=int(x)

d.append(x)

return sum(d)

print digit_sum(1234)

su=0

d=[]

def digit_sum(n):

n=str(n)

for x in n:

x=int(x)

d.append(x)

return sum(d)

print digit_sum(1234)

because declaring `su`

and `d`

is not inside the function, calling the function multiply times with different integer values it wouldn't work correctly

Or, if i hire you to write this function, you give me the python script, and i then try to import the function to my script (`from yourscript import digit_sum`

), i get an error because `su`

and `d`

are not defined

the function itself should be fully equipped to calculate the sum of the digits