简体   繁体   中英

Turtle Library in Python

I am having a huge issue using the turtle library. I have to write my initials AR for an assignment. Can anyone help?

import turtle

turtlescreen

turtle.pos(400,400)
turtle.forward()

Here is the code I am trying to use. I am trying to right my initial "AR" with it.

You've managed to cram three errors into four lines of code. First, you don't need this and it's an error:

turtlescreen

so toss it. Second, the pos() function returns the current turtle postion, not set it. So instead of:

 turtle.pos(400,400)

You want:

turtle.setpos(400, 400)

and finally, as @Jamie notes, you need to pass a distance (in pixels) to forward() . So instead of:

 turtle.forward()

Something like he suggests:

turtle.forward(15)

Complete code:

import turtle

turtle.setpos(400, 400)
turtle.forward(15)

turtle.done()

Your turtle.forward() requires an input variable in pixels. See the documentation for turtle.forward :

Move the turtle forward by the specified distance , in the direction the turtle is headed.

Try changing: turtle.forward()

to something like: turtle.forward(15)

There's a few mistakes I can see. Firstly, there is no command called turtlescreen so you can remove that. Next, instead of tom.pos try using tom.setpos(x, y) or tom.goto (x, y). Lastly, you should put a value in tom.forward (length). I also recommend going through the Python Turtle documentation, https://docs.python.org/3.3/library/turtle.html?highlight=turtle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM