Home >Backend Development >Python Tutorial >How to draw a rectangle in Python
Basic steps to draw a rectangle with python:
First download and install the python program.
Find the python IDLE tool on our own computer.
2. Then open IDLE, create a new file, and name it test1.py
Related recommendations: "python video tutorial"
#3. Then we start editing the code. First, we need to clarify the functions used include turtle.left, turtle.right and turtle.forward functions. The code is as follows:
import turtle turtle.left(90) turtle.forward(100)
Call the turtle first, turn left 90, go straight 100
turtle.right(90) turtle.forward(150) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(150)
Turn right, go straight, turn right, go straight, it’s OK.
Every angle is 90 degrees.
operation result
The above is the detailed content of How to draw a rectangle in Python. For more information, please follow other related articles on the PHP Chinese website!