Well, you want to process the string representing the number, iterating over the digits, not the number itself (which is an abstract entity that could be written differently, like "CX" in Roman numerals or "0x6e" hexadecimal (both for 110) or whatever).
Therefore:
inp = input('Enter a number:')
n = 0
for digit in inp:
n = n + int(digit)
print(n)
Note that the n = 0
is required (someplace before entry into the loop). You can't take the value of a variable which doesn't exist (and the right hand side of n = n + int(digit)
takes the value of n
). And if n
does exist at that point, it might hold something completely unrelated to your present needs, leading to unexpected behaviour; you need to guard against that.
This solution makes no attempt to ensure that the input provided by the user is actually a number. I'll leave this problem for you to think about (hint: all that you need is there in the Python tutorial).