2019-01-30
阅读量:
1029
python报错:列表不能解释为整数
输入以下内容时,会抛出一个错误,如下所示:
list" object cannot be interpreted as an integer.
l = list(range(0, 998002)) # the number "998002" is the largest number that can be produced by multiplying
two 3-digit numbers.
def palindrome():
for a in range(l): # the problem seems to be in the foor loop....
for b in (l):
pal = a * b
x = str(pal)
y = str(a)
z = str(b)
if y == 3 and z == 3 and x[0:len(pal)] == x[::-1]:
return pal
问题解决:
pal = a * b
int
对象没有长度属性。
LEN(PAL)
你的程序是否试图找到所有由两个三位数字组成的palidromes?或者只测试两个数字的产品是否是回文?
测试一个数字是不是三位数的简单方法是,
x not in range(100, 1000)
这将给出True是x小于或大于三位数。






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论