Python列表解释(w/Turtles)



小蟒蛇问题,如何让乌龟根据[(160, 20), (-43, 10), (270, 8), (-43, 12)]移动,第一个数字是转弯角度,第二个数字是行进距离。

我的尝试:

print('Question 11')
import turtle
wn = turtle.Screen()
wn.bgcolor("hot pink")
tess = turtle.Turtle()
tess.shape("turtle")
tess.color("blue")
def path(x):
    for a, b in len(x): # Not so sure about this line.
      tess.forward(a)
      tess.right(b)
l = [(160, 20), (-43, 10), (270, 8), (-43, 12)]
path(l)
wn.mainloop()

我得到的错误:

TypeError:"list"对象不能被解释为整数

TypeError:"int"对象不是可迭代的

我不熟悉海龟,但下面一行:

for a, b in len(x): # Not so sure about this line.

这一行是错误的:x,因为下面的代码表示一个列表。len(x)返回一个整数,但integer是不可迭代的。

你的意思是:

for a, b in x:

而是您的代码。

最新更新