sidharth
sidharth

Reputation: 21

turtle showing error which used to work fine earlier

import turtle
t = turtle.Turtle()
t.forward(100)
t.done()
  1. this code is returning an error like this NameError: name 'turtle' is not defined
  2. I have tried to use turtle but it doesn't seem to be working the way it is shown in the code.
  3. I have tried referring to various sources but could not find the fix

Upvotes: 1

Views: 50

Answers (1)

Red
Red

Reputation: 27567

The problem lies on this line:

t.done()

You see, you defined t as a Turtle object, and Turtle objects have no attribute done.

The done() attribute belongs to the turtle module itself, so instead of t.done(), it's turtle.done():

import turtle
t = turtle.Turtle()
t.forward(100)
turtle.done()

Upvotes: 1

Related Questions