这是我的代码:
import math
print "Hey, lets solve Task 4 :)"
number1 = input ("How many digits do you want to look at? ")
number2 = input ("What would you like the digits to add up to? ")
if number1 == 1:
cow = range(0,10)
elif number1 == 2:
cow = range(10,100)
elif number1 == 3:
cow = range(100,1000)
elif number1 == 4:
cow = range(1000,10000)
elif number1 == 5:
cow = range(10000,100000)
elif number1 == 6:
cow = range(100000,1000000)
elif number1 == 7:
cow = range(1000000,10000000)
elif number1 == 8:
cow = range(10000000,100000000)
elif number1 == 9:
cow = range(100000000,1000000000)
elif number1 == 10:
cow = range(1000000000,10000000000)
number3 = cow[-1] + 1
n = 0
while n < number3:
number4 = list(cow[n])
n += 1
我正在寻找一个循环,以便对于列表中的每个元素,它将分解为每个字符。例如,假设数字137
在列表中,那么它将变成[1,3,7]
。然后,我想将这些数字加在一起(我还没有开始,但是我对如何做有一些想法)。
但是,我不断收到错误消息
TypeError: 'int' object is not iterable
当我尝试运行此程序时。
我究竟做错了什么?
list(cow[n])
做什么?