该函数应该循环,每次将圆的大小减小10并绘制一个新圆,直到大小小于或等于0.我缺少什么
def circle(x):
turtle.up()
turtle.goto(0,0)
turtle.down()
turtle.color("blue")
turtle.circle(x)
if x>0:
turtle.up()
turtle.goto(0,0)
turtle.down()
turtle.color("blue")
turtle.circle(x-10)
else:
turtle.up()
turtle.goto(0,0)
turtle.down()
turtle.color("blue")
turtle.circle(x)
print(circle(80))
答案 0 :(得分:4)
这是一个工作版本。添加了递归circle(x-10)
,删除了冗余代码,添加了turtle.done()
以阻止应用崩溃。
import turtle
def circle(x):
turtle.up()
turtle.goto(0,0)
turtle.down()
turtle.color("blue")
turtle.circle(x)
if x>0:
circle(x-10)
circle(80)
turtle.done()
答案 1 :(得分:1)
带有显式循环的版本:
import turtle
def circle(x):
while x > 0:
turtle.up()
turtle.goto(0,0)
turtle.down()
turtle.color("blue")
turtle.circle(x)
x -= 10;
circle(80)
turtle.done()
答案 2 :(得分:0)
def ring_draw(dia,x0,y0):
to_return=[]
rad = dia / 2
for x in xrange(x0+(rad+2)):
for y in xrange(y0+(rad+2)):
z0 = abs(x - x0)
z1 = abs(y - y0)
z2 = z0**2 + z1**2
if rad**2 >= z2:
to_return.append([x,y])