【发布时间】:2016-09-24 20:16:06
【问题描述】:
无法弄清楚为什么会出现此错误:AttributeError: 'str' object has no attribute 'forward'
编写一个名为 drawSquare 的函数。函数 drawSquare 需要两个 参数:一个乌龟,t和一个整数,length,即正方形的边长。
函数drawSquare应该使用参数t来绘制正方形。 不要对海龟的初始向上/向下状态做任何假设, 它在屏幕上的位置或其方向。函数drawSquare 应该从海龟的初始位置开始绘制,并且 方向。当 drawSquare 返回时,乌龟应该再次在它的 初始位置和方向。 重复操作必须使用循环。
import turtle
s = turtle.Screen()
t = turtle.Turtle()
def drawSquare(t, length):
for i in range(4):
t.forward(length)
t.right(90)
drawSquare('turtle', 100)
【问题讨论】: