import turtle as t
def DrCircle(n,f):
t.penup()
t.goto(0,-n)
t.pendown()
t.pencolor('red')
t.begin_fill()
t.circle(n)
t.fillcolor(f)
t.end_fill()
for i in range(160,30,-60):
for z in ['yellow','blue','green']:
DrCircle(i,z)
t.hideturtle()
t.done()
python是通过缩进来判断语句的归属。将语句for z in ['yellow','blue','green']:
和语句DrCircle(i,z)
各增加一个缩进。代码和运行结果如下:
import turtle as t
def DrCircle(n,f):
t.penup()
t.goto(0,-n)
t.pendown()
t.pencolor('red')
t.begin_fill()
t.circle(n)
t.fillcolor(f)
t.end_fill()
for i in range(160,30,-60):
for z in ['yellow','blue','green']:
DrCircle(i,z)
t.hideturtle()
t.done()
但是这个并不是楼主想要的结果,我猜测楼主想得到这样的结果:
思路是用两个数组分别存半径和颜色,附上代码:
import turtle as t
def DrCircle(n,f):
t.penup()
t.goto(0,-n)
t.pendown()
t.pencolor('red')
t.begin_fill()
t.circle(n)
t.fillcolor(f)
t.end_fill()
r = range(160,30,-60)
c = ['yellow','blue','green']
for i in range(len(r)):
DrCircle(r[i], c[i])
t.hideturtle()
t.done()