Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.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类型错误:';列表';对象不能解释为整数_Python_Typeerror_Turtle Graphics - Fatal编程技术网

Python类型错误:';列表';对象不能解释为整数

Python类型错误:';列表';对象不能解释为整数,python,typeerror,turtle-graphics,Python,Typeerror,Turtle Graphics,我在这方面是新手,所以请容忍我,我一直收到错误TypeError:“list”对象不能解释为整数。我不知道如何修复这个错误。任何帮助都将不胜感激 import turtle wn = turtle.Screen() bob = turtle.Turtle() List = ["red", "orange", "yellow", "green", "blue", "violet"] List2 = [8, 7, 6, 5, 4, 3] C = (-1) S = (9) bob.speed(2

我在这方面是新手,所以请容忍我,我一直收到错误
TypeError:“list”对象不能解释为整数。我不知道如何修复这个错误。任何帮助都将不胜感激

import turtle

wn = turtle.Screen()

bob = turtle.Turtle()
List = ["red", "orange", "yellow", "green", "blue", "violet"]
List2 = [8, 7, 6, 5, 4, 3]
C = (-1)
S = (9)

bob.speed(2)
bob.penup()
bob.left(90)
bob.forward(70)
bob.right(90)
bob.pendown()
def drawAnyShape(Side):
    for i in range(0,Side):
        bob.forward(50)
        bob.right(360/Side)

for i in range(3,9):
    S = (S-1)
    C = (C+1)
    bob.begin_fill()
    bob.color(List[C])
    drawAnyShape([S])
    bob.end_fill()

wn.mainloop()
请试试这个:

import turtle

wn = turtle.Screen()

bob = turtle.Turtle()
List = ["red", "orange", "yellow", "green", "blue", "violet"]
List2 = [8, 7, 6, 5, 4, 3]
C = (-1)
S = (9)

bob.speed(2)
bob.penup()
bob.left(90)
bob.forward(70)
bob.right(90)
bob.pendown()
def drawAnyShape(Side):
    for i in range(0,Side):
        bob.forward(50)
        bob.right(360/Side)

for i in range(3,9):
    S = (S-1)
    C = (C+1)
    bob.begin_fill()
    bob.color(List[C])
    drawAnyShape(S)  # <- problem is here!
    bob.end_fill()

wn.mainloop()
导入海龟
wn=tutle.Screen()
bob=海龟。海龟()
列表=[“红色”、“橙色”、“黄色”、“绿色”、“蓝色”、“紫色”]
清单2=[8,7,6,5,4,3]
C=(-1)
S=(9)
鲍勃:速度(2)
鲍勃·彭普
鲍勃:左(90)
鲍勃.前锋(70)
鲍勃:对(90)
bob.pendown()
def drawAnyShape(侧面):
对于范围内的i(0,侧面):
鲍勃,前进(50)
鲍勃:右(360/侧)
对于范围(3,9)内的i:
S=(S-1)
C=(C+1)
鲍勃,开始加油
bob.color(列表[C])

drawAnyShape([S])
您使用列表调用它,但是尝试使用该列表作为
范围的参数
drawAnyShape([S])
->
def drawAnyShape(Side):
,Side是单元素列表,然后将其传递给
范围(0,Side)
<代码>范围(0,['a',b',c'])
(或任何其他列表)不是正确的调用。请您解释一下原始代码中的错误以及您更改了什么来修复它?如上所述,您有
[S]
,这是一个值为S的单例列表。在此版本中,传递变量
S
,这是函数
drawAnyShape
范围(0,侧面)
的预期值。