Help I am stuck and it keeps telling me:

function has no positive integer and "int objetc is not iterable"


the url is the same for everyone, it checks for user to load your personal code

Please copy paste your code to the forum, preferable using markup:

So the indent will show


n=int(input('input a number'))
def digit_sum(n):
    for i in n:
        i +=int(i)
    return (sum(result))


this line:


you cast n to a string to cast it back to a integer. Could you explain why?


i +=int(i)

you are adding int(i) to the for loop iterator, why? You defined a beautiful variable called total, which i assume has as purpose to store the total?

don't use sum(), it is for lists. You don't have a list.


n=int(str(n)) because the hint reads "One way might be to convert the integer to a string with str(), divide it up, and turn the substrings back into integers with int() to do the addition."

I dont have a variable called total. I only have a variable called result so you have confused me

Anyway please help me correct it because I seem not to understand your feedback. please forgive for that


you do the sub-string conversion in your for loop:

i +=int(i)

to get the result.

but here:


you are converting the whole string back to an integer after casting it to a string, not the sub-string.

That is indeed a mistake of me, that should be result:
You defined a beautiful variable called result, which i assume has as purpose to store the result?


am stuck again


you still add i to i instead of result, result should have the sum of the numbers. adding to the iterator doesn't make much sense since its get overwritten every iteration of the loop


my mistake
got it now
i changed to
result =result+i

Thanks alooooot
much appreciated