使用Python绘制多边形

  turtle是Python内置的图形库,在这里,我们需要知道正多边形内角计算公式: 内角=(边数-2)*180/边数
可选项:提示输入一种颜色,进行填充。 本程序运行环境是Python3的IDLE。
import turtle
##python中的图形库

num = int(input("Please input the num of the polygon: "))
color = input("Please input the color of the fillcolor:")
turtle.fillcolor(color)
angle = 180 - (num -2) * 180 / num
turtle.begin_fill()
for i in range(num):
    turtle.forward(100)
    turtle.right(angle)
turtle.end_fill()
turtle.done()
使用Python绘制多边形_第1张图片


你可能感兴趣的:(turtle)