i would place this:
total = 0
inside the function, we talked about this.
y = int(x)
are redundant. you still have
n which contains the integer, and we loop over
x (string of the number) anyway, so we don't need a list. So i suggest to remove this two lines.
a.append(y) would simply result in:
, not very useful, we still have integers (which are not iterable). So i suggest not to use the list at all
okay, then here:
for i in range(0, len(n)):
n is a integer.
len() doesn't work for an integers. we convert our integer to a string, we can use the string to loop over our number. Personally i would just get rid of
range() as well, but that it your choice.
okay, now that we loop over our string (did you figure this out?) we can start adding total, we can simply use
+ for this, basic math, probably taught somewhere in the first track.
here is an example:
total = 0
total = total + 5
print total # will print 5
that should help you.
Also, a f unction ends the moment a return keyword is reached, this currently happens in the first iteration of your loop, so the loop simply breaks at the end of the first iteration.
Place the return outside the loop so the whole loop can run