turtle.sety() function in Python

The turtle.sety() function in Python sets the turtle’s y-coordinate to the given value, moving it vertically. The x-coordinate and heading remain unchanged.

Syntax: turtle.sety(y)
Parameters: y: a number (integer or float) representing the new y-coordinate.

Let us see an example to implement the turtle.sety() function in Python:

Demo6.py

# turtle.sety() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
t = turtle.Turtle()

t.sety(100)     # Set y coordinate to 100, x remains same
t.sety(-100)    # Set y coordinate to -100

window.exitonclick()

The following is the output:

turtle.sety() in Python Turtle

In the above code, we followed the below steps:

  1. Import the module: import turtle loads Python’s turtle graphics library for drawing.
  2. Create the screen: window = turtle.Screen() opens the drawing window.
  3. Create the turtle: t = turtle.Turtle() creates the turtle (the pen) you’ll control.
  4. Move to y = 100: t.sety(100) moves the turtle vertically to y = 100 while keeping the current x the same. It doesn’t change heading and draws a line if the pen is down (default).
  5. Move to y = -100: t.sety(-100) moves vertically to y = -100, same x, again drawing a line if the pen is down.
  6. Close on click: window.exitonclick() keeps the window open until you click inside it, then closes.

If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

turtle.setx() function in Python
turtle.seth() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment