int object is not iterable?

前端 未结 11 843
天命终不由人
天命终不由人 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:29

    Side note: if you want to get the sum of all digits, you can simply do

    print sum(int(digit) for digit in raw_input('Enter a number:'))
    

提交回复
热议问题