turtle.setx() 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.setx()
This method is used to set the turtle’s first coordinate to x, leave the second coordinate unchanged. Here, whatever the position of the turtle is, it set the x coordinate to given input keeping y coordinate unchanged.
Syntax : turtle.setx(x)
Parameter:
x: 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 turtle
print (turtle.position())
turtle.setx( 30 )
print (turtle.position())
turtle.setx( - 50 )
print (turtle.position())
|
Output :
(0.0, 0.0)
(30.0, 0.0)
(-50.0, 0.0)
Example 2 :
Python3
import turtle
turtle.left( 90 )
for i in range ( 4 ):
turtle.forward( 100 )
turtle.right( 90 )
turtle.forward( 20 )
turtle.right( 90 )
turtle.forward( 100 )
turtle.up()
turtle.setx( 40 * (i + 1 ))
turtle.down()
turtle.left( 180 )
|
Output :
Last Updated :
07 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...