這是代碼在書Thinkpython 2e。如何在Python中成爲一個圓圈?
import turtle
import math
bob = turtle.Turtle()
def polygon(t, n, length):
angle = 360/n
for i in range(n):
t.fd(length)
t.lt(angle)
def circle(t, r):
circumference = 2 * math.pi * r
n = 50
length = circumference/n
polygon(t, n, length)
circle(bob,50)
turtle.mainloop()
我不明白怎麼可能成爲一個圓形,我認爲它將是一個50邊多邊形,我說得對嗎?
它是50邊多邊形,但看起來幾乎像圓圈。 – furas
請注意,這裏的註釋和docstring是有用的,理想情況下,你會得到一些信息,比如''「」近似一個有50個常規圓圈的圓圈。「」''打破混亂... – Julien