Reputation: 9
Can't figure out why am I getting this error: AttributeError: 'str' object has no attribute 'forward'
Write a function named drawSquare. The function drawSquare takes two parameters: a turtle, t and an integer, length, that is the length of a side of the square.
The function drawSquare should use the parameter t to draw the square. Do not make any assumptions about the initial up/down state of the turtle, its position on the screen or its orientation. The function drawSquare should begin drawing with the turtle at its initial position and orientation. When drawSquare returns, the turtle should again be in its initial position and orientation. You must use a loop for repeated operations.
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)
Upvotes: -1
Views: 459
Reputation: 216
In the last line, when you made the call to your drawSquare
function you passed the string 'turtle'
- pass in your Turtle
object t
instead.
Upvotes: 2