int object is not iterable?

前端 未结 11 884
天命终不由人
天命终不由人 2020-12-01 11:19
inp = int(input(\"Enter a number:\"))

for i in inp:
    n = n + i;
    print (n)

... throws an error: \'int\' object is not iterable<

11条回答
  •  天命终不由人
    2020-12-01 11:24

    try:

    for i in str(inp):
    

    That will iterate over the characters in the string representation. Once you have each character you can use it like a separate number.

提交回复
热议问题