赞
踩
import turtle for i in range(8): #一共有八列 for j in range(8):#每一行有八个格 turtle.forward(37.5) if j % 2 == 0:#判断是否为第奇数个格(是否画黑色格) if i % 2 ==0:#判断是否为奇数行(调整画黑色正方形时小海龟的转向) turtle.begin_fill()#开始填充 for s in range(4):#画正方形 turtle.left(90) turtle.forward(37.5) turtle.end_fill()#结束填充 else :#如果为偶数行,则小海龟画正方形时不断向右转向 turtle.begin_fill() for s in range(4): turtle.right(90) turtle.forward(37.5) turtle.end_fill() if i % 2 == 0:#一行画完之后,判断小海龟该向哪个方向转向,从而画下一行 turtle.left(90) turtle.forward(37.5) turtle.left(90) else: turtle.right(90) turtle.forward(37.5) turtle.right(90) turtle.forward(300)#画完最后一行时,补齐上方边线 turtle.done()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。