-3

I'm trying to write turtle code with turtle shape and a color and drawing T letter. The following is my code: It gives me run time Error with shape! Please help me to correct it! Thanks

import turtle # Import the required library

ft = turtle.Turtle
ft.shape("turtle")
ft.color(255)
ft.forward(100)
ft.backward(50)
ft.left(90)
ft.forward(200)
kederrac
  • 15,339
  • 4
  • 25
  • 45
Far
  • 1

3 Answers3

0

You have to change the second line from:

ft = turtle.Turtle

to

ft = turtle.Turtle()

After you make the change variable ft will point to an instance of the class Turtle from the turtle module and you will be able to call methods of this object, like shape, color, etc.

piokuc
  • 22,730
  • 9
  • 64
  • 94
0

There are a couple of errors in this code. Along with the missing parentheses that @piokuc noted:

ft = turtle.Turtle()

This line will also cause an error:

ft.color(255)

The color() function is fairly flexible about it's argument:

color(colorstring), color((r,g,b)), color(r,g,b)

But ft.color(255) is invalid for two reasons. First, it's not a valid argument and second it's assuming a 0 - 255 color scale which is incorrect. The default color mode for turtle is 0.0 - 1.0 unless you change it with turtle.colormode(255).

Finally, you might want to end with turtle.done() at the bottom of your code, unless you're running under a development environment that doesn't require it.

PS: Your 'T' is upsidedown!

cdlane
  • 33,404
  • 4
  • 23
  • 63
0

You don't need to do ft = turtle.Turtle() , Rather just import turtle, then the function for the shape is shape(name = "turtle").

This is what the program should look like:

import turtle
shape(name = "turtle")
color("blue") #The color you want
forward(100)
backward(50)
left(90)
forward(200)