import turtleimport timeimport math def polygon(bob,n,r): jiaoDu = 360/n juLi=2*r*math.sin(jiaoDu/180*math.pi/2) bob.pu() bob.fd(r) bob.lt(90+jiaoDu/2) bob.pd() for i in range(n): bob.fd(juLi) bob.lt(jiaoDu) time.sleep(0.5) n=int(input("请输入边数:"))r=float(input("请输入半径:"))bob=turtle.Turtle()polygon(bob,n,r)turtle.mainloop()
时间: 2024-10-30 23:28:20