Usage example of turtle.right() method in Python

The turtle module provides turtle graphics primitives in an object-oriented and procedural-oriented manner. Because it uses Tkinter for the underlying graphics, it requires a version of Python with Tk support installed.

 

turtle.right()

The turtle.right() method is used to change the direction of the turtle by its parameter value. It moves the turtle's head in one direction.

The syntax is as follows:

turtle.right(angle)

The argument it accepts is angle{a number (integer or float)}. Therefore, it turns right in units of degrees. (The units default to degrees, but can be set via the degree() and radian() functions.) The angular direction depends on the mode.

Here is an implementation of the above method with some examples:

Example 1:

Python3

# importing package
import turtle
  
  
# move the turtle forward by 
# 100 unit distance in the
# direction of head of turtle
turtle.forward( 100 )
  
# change the direction of turtle
# by 90 degrees to the right.
turtle.right( 90 )
  
# move the turtle forward by
# 100 unit distance in the 
# direction of head of turtle
turtle.forward( 100 )

output:

Example 2:

Python3

# importing package
import turtle
  
  
# Loop for pattern
for i in range ( 10 ):
    
   # move the turtle forward by 
   # 100+variable unit distance
   # in the direction of head of turtle
   turtle.forward( 100 + 10 * i)
    
   # change the direction of turtle
   # by 90 degrees to the right.
   turtle.right( 90 )

output:

First of all, your interview preparation enhances your data structure concepts through: Python DS course.

For more information about Python development, please refer to: lsbin - IT development technology : https://www.lsbin.com/

Check out more Python-related content below:

Guess you like

Origin blog.csdn.net/u014240783/article/details/115335868