Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python %的typeerror不支持的操作数类型:';列表';和';int';_Python_List_Int_Typeerror - Fatal编程技术网

Python %的typeerror不支持的操作数类型:';列表';和';int';

Python %的typeerror不支持的操作数类型:';列表';和';int';,python,list,int,typeerror,Python,List,Int,Typeerror,代码如下: list = [2, 3, 5, 7, 11, 13] list2 = [range(list[-1], 2000000)] y =11 x = 1 v = list[-1]>= x while list[-1] ** 2 < 2000000: y= y + 2 prime = True while prime == True: for x in list: if x * 2 < y:

代码如下:

list = [2, 3, 5, 7, 11, 13]
list2 = [range(list[-1], 2000000)]
y =11
x = 1
v = list[-1]>= x
while list[-1] ** 2 < 2000000:
    y= y + 2
    prime = True
    while prime == True:    
        for x in list:
            if x * 2 < y:   
                if y % x == 0:
                    prime = False
                    break
        if prime == True:
            list.append(y)
            prime = False
print sum(list)

for u in list:
    for w in list2:
        if u * u < w:
            if w % u == 0:
                list2.pop(w)
print list
print sum(list) + sum(list2)
list=[2,3,5,7,11,13]
列表2=[范围(列表[-1],2000000)]
y=11
x=1
v=列表[-1]>=x
而列表[-1]**2<2000000:
y=y+2
素数=真
当prime==True时:
对于列表中的x:
如果x*2
正如你所看到的,这是一个基本的程序,它创建一个筛子,然后为筛子放入高达200万的数字。这是为欧拉项目准备的,我在学习编程的过程中尝试测试我的技能

现在,错误,这篇文章的标题是在第23行。发生这种情况的原因是什么?

range()
已经返回了一个列表,但您将其放入了一个新列表中:

list2 = [range(list[-1], 2000000)]
这将产生一个包含列表的列表,并且随后将
w
设置为全范围。只需拆下那里的支架

>>> [range(5)]
[[0, 1, 2, 3, 4]]
>>> range(5)
[0, 1, 2, 3, 4]

我删除了你文章中的一大块内容,只是为了关注问题本身。有关堆栈溢出本身的帮助,请询问。关于格式,请参见示例。Python编程备注:不要命名变量
list
,已经有一个内置类型
list
,您现在已经对它进行了跟踪。您的评论非常棒,非常有帮助。@goldenparrot:OP(在文章的长版本中)说他们在格式方面做得最好,但这是一个常见的发布错误,不一定是原始代码中的任何内容。在这种情况下可能会出现语法错误。谢谢。我接受了答案。我会投赞成票,但我没有这个名声。