Home >Backend Development >Python Tutorial >How to draw a rectangle in Python

How to draw a rectangle in Python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-11 15:44:4810869browse

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.

How to draw a rectangle in Python

2. Then open IDLE, create a new file, and name it test1.py

Related recommendations: "python video tutorial"

How to draw a rectangle in Python

#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

How to draw a rectangle in Python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn