gpt4 book ai didi

Python 类型错误 : 'list' object cannot be interpreted as an integer

转载 作者:行者123 更新时间:2023-11-28 19:14:50 24 4
gpt4 key购买 nike

我是新手,所以请多多包涵,我一直收到错误 TypeError: 'list' object cannot be interpreted as an integer。我不确定如何修复此错误。任何帮助将不胜感激。

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()

关于Python 类型错误 : 'list' object cannot be interpreted as an integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34887601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com