Home  >  Article  >  Backend Development  >  What is the code for drawing a square in python?

What is the code for drawing a square in python?

coldplay.xixi
coldplay.xixiOriginal
2020-06-17 14:12:4230763browse

What is the code for drawing a square in python?

What is the code for drawing a square in python?

The code for python to draw a square is:

import turtle         #导入
turtle.title("画正方形")
turtle.pensize(5)      #画笔大小为5
turtle.pencolor("red") #画笔颜色为红
turtle.fillcolor("green")   #填充颜色为绿
turtle.begin_fill()      #开始填充
for i in range(4):       #循环四次
    turtle.forward(200)   #前进200
    turtle.left(90)      #左转90度
turtle.end_fill()       #结束填充
turtle.done()           #导入结束

Recommended tutorial: "python video tutorial"

The above is the detailed content of What is the code for drawing a square 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