Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

I'm trying to build the snake game using the python module turtle. This is my code

import turtle

#set up the screen

wn = turtle.Screen()

wn.title("snake game")

wn.bgcolor("Blue")

wn.setup(width=600, height=600)

wn.tracer(0)

#Snake Head

head = turtle.Turtle()

head.speed(0)

head.Shape("Square")

head.color("Black")

head.penup()

head.goto(0, 0)

head.direction = "stop"

turtle.mainloop()

Error:

  head.Shape("Square")

AttributeError: 'Turtle' object has no attribute 'Shape'

1 Answer

0 votes
by (25.1k points)

The error you are getting is called an AttributeError, the error message also suggests that it is in the code 'head.Shape('Square')'. 

An AttributeError suggests that you are getting this error because you are tring to access an attribute or method that does not exist on the object. In your case it is the method named Shape on the head object. This is because you are capitalizing the first letter of the word Shape and it should be shape. 

So you can resolve this error by replacing

head.Shape('Square')

to

head.shape('square')

Also notice the parameter Square should also have its first letter lower cased as square.

You can learn more about python and it's methods using this video:

Browse Categories

...