Reputation: 27
The function is supposed to loop, each time decreasing the size of the circle by 10 and drawing a new circle, until the size is less than or equal to 0. What am i missing
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))
Upvotes: 2
Views: 3827
Reputation: 1
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])
Upvotes: 0
Reputation: 682
Version with explicit loop:
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()
Upvotes: 1
Reputation: 682
Here is a working version. Added recursion circle(x-10)
, removed redundant code, added turtle.done()
to stop the app from crashing.
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()
Upvotes: 4