Tuesday, November 19, 2024
Google search engine
HomeLanguagesturtle.sety() function in Python

turtle.sety() function in Python

The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.

turtle.sety()

This method is used to set the turtle’s second coordinate to y, leaving the first coordinate unchanged. Here, whatever the position of the turtle is, it set the y coordinate to given input keeping the x coordinate unchanged.

Syntax : turtle.sety(y) 
 

Parameter: 

y: a number (integer or float), it is the only one required argument.

Below is the implementation of the above method with some examples :

Example 1 :

Python3




# import package
import turtle
 
 
# check the turtle position
print(turtle.position())
 
# set the y coordinate
turtle.sety(30)
 
# check the turtle position
print(turtle.position())
 
# set the y coordinate
turtle.sety(-50)
 
# check the turtle position
print(turtle.position())


 

 

Output :

 

(0.0, 0.0)
(0.0, 30.0)
(0.0, -50.0)

 

Example 2 :

 

Python3




# import package
import turtle
 
# loop for pattern
for i in range(4):
   
  # motion
  turtle.forward(100)
  turtle.right(90)
  turtle.forward(20)
  turtle.right(90)
  turtle.forward(100)
   
  # set the y coordinate
  turtle.up()
  turtle.sety(-40*(i+1))
  turtle.down()
   
  # change the direction
  turtle.left(180)


 

 

Output :

 

 

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments