How to draw a rectangle in Python

爱喝马黛茶的安东尼
Release: 2019-06-19 13:41:02
Original
10837 people have browsed it

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)
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template