If k is 0, you end up dividing by 0, an impossibility.
I changed up some of your code, and came up with this workable solution:
n=int(raw_input("enter the number: "))
total = 0
for i in range (0,k):
We take the number in as you did, and store its length in the variable
k. Then, things get a little different. Instead of using a list to contain each digit, then adding them up, we just simply add them to a total variable that is contained locally inside the function. Then, once all digits have been added, we return the variable, to find the desired result. Using string indices, we can take the desired position in our string, and convert that to an integer. Once it's an integer, it's simple enough to just add it to our total. Using the
i variable defined in the for loop, we know which iteration the loop is on, and which string index to use. (Hence,
str(n)[i].) This method also eliminates the need to use the math library, and its functions.
As a side note, make sure to define functions before you call them. If you don't, you're asking for errors.