【发布时间】:2020-06-19 18:07:30
【问题描述】:
我是编码新手,从一本名为 Think Python 的书入手。在下面的练习中 - 我必须使用 Turtle 图形来编写用于绘制多边形和圆形的函数。解决方法如下:
#draw polygon
import turtle
bob = turtle.Turtle()
def Polygon(t,length,n):
t = bob
for i in range(n):
bob.fd(length)
bob.rt(360/n)
#draw circle
import math
def Circle(t,r):
Circumference = 2*math.pi*r
n=int(Circumference/3)+1
length = Circumference/n
Polygon(t,length,n)
但是有人可以向我解释最后一行Polygon(t,length,n) 发生了什么吗?我不明白这是在做什么,为什么只有包含这一行才会运行程序。
【问题讨论】:
标签: math automatic-ref-counting turtle-graphics pi