DIGIT_SUM :it's showing error even though my code is working fine!



def digit_sum(n):
for x in n:
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


yep u r ryt i too discovered it now! thanx for ur quick help!