turtle.right() function in Python

The turtle.right() function in Python rotates the turtle clockwise (right) by a specified angle. This only changes the turtle’s heading, not its position.

Syntax: turtle.right(angle)
Parameters: angle: a number (integer or float) representing the degrees to turn.

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

Demo4.py

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

import turtle

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

t.forward(100)
t.right(90)     # Turn right 90 degrees
t.forward(100)

window.exitonclick()

The following is the output:

turtle.right() 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 simple drawing.
  2. Create the screen: window = turtle.Screen() opens the drawing window.
  3. Create the turtle: t = turtle.Turtle() makes a turtle (the pen) you control.
  4. Move forward: t.forward(100) draws a 100-unit line in the current direction.
  5. Turn right: t.right(90) rotates the turtle 90 degrees clockwise without moving.
  6. Move forward again: t.forward(100) draws another 100-unit line in the new direction, forming an “┘” shape.
  7. Close on click: window.exitonclick() keeps the window open until you click, then closes it.

 


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.left() function in Python
turtle.setx() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment