Files
mixly3/boards/default/python_mixpy/examples/海龟画图/py/海龟画图07闪烁星星_02正n角星.py
2024-07-19 10:16:00 +08:00

22 lines
640 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import turtle
tina= turtle.Turtle()
tina.pencolor("#ff0000")
tina.fillcolor("#ffff00")
n = int(turtle.numinput("输入","请输入尖角个数奇数或4的倍数",20,minval = 0,maxval = 100))
while n % 4 == 2:
tina.clear()
tina.write("无法一笔画出" + str(n) + "角星",False,align="left",font=("Arial",16,"normal"))
n = int(turtle.numinput("输入","请输入尖角个数:",20,minval = 0,maxval = 100))
tina.clear()
if n % 4 == 0:
angle = 180 - 360 / n
else:
angle = 180 - 180 / n
tina.begin_fill()
for i in range(0, n, 1):
tina.forward(200)
tina.right(angle)
tina.end_fill()
tina.hideturtle()