用python海龟库画出5*5方格,涂出一个叉
自己做的,多指教。。。{:5_91:}from turtle import*
t = Turtle()
t.shape("turtle")
t.color("black")
t.speed(500)
c = 0
b = 0
while c < 5:
c = c + 1
a = 1
t.right(90)
t.forward(20)
t.left(90)
t.down()
if a < 6:
for i in range(5):
if c == 1 and a == 1 or c == 1 and a == 5:
t.begin_fill()
t.fillcolor('red')
for i in range(4):
t.forward(20)
t.left(90)
t.end_fill()
for i in range(4):
t.forward(20)
t.left(90)
t.forward(20)
a = a + 1
t.up()
t.right(180)
t.forward(100)
t.left(90)
t.forward(20)
t.left(90)
t.down()
a = 1
c = c + 1
for i in range(5):
if c == 2 and a == 2 or c == 2 and a == 4:
t.begin_fill()
t.fillcolor('red')
for i in range(4):
t.forward(20)
t.left(90)
t.end_fill()
for i in range(4):
t.forward(20)
t.left(90)
t.forward(20)
a = a + 1
t.up()
t.right(180)
t.forward(100)
t.left(90)
t.forward(20)
t.left(90)
t.down()
a = 1
c = c + 1
for i in range(5):
if c == 3 and a == 3:
t.begin_fill()
t.fillcolor('red')
for i in range(4):
t.forward(20)
t.left(90)
t.end_fill()
for i in range(4):
t.forward(20)
t.left(90)
t.forward(20)
a = a + 1
t.up()
t.right(180)
t.forward(100)
t.left(90)
t.forward(20)
t.left(90)
t.down()
a = 1
c = c + 1
for i in range(5):
if c == 4 and a == 2 or c == 4 and a == 4:
t.begin_fill()
t.fillcolor('red')
for i in range(4):
t.forward(20)
t.left(90)
t.end_fill()
for i in range(4):
t.forward(20)
t.left(90)
t.forward(20)
a = a + 1
t.up()
t.right(180)
t.forward(100)
t.left(90)
t.forward(20)
t.left(90)
t.down()
a = 1
c = c + 1
for i in range(5):
if c == 5 and a == 1 or c == 5 and a == 5:
t.begin_fill()
t.fillcolor('red')
for i in range(4):
t.forward(20)
t.left(90)
t.end_fill()
for i in range(4):
t.forward(20)
t.left(90)
t.forward(20)
a = a + 1 太多重复语句了{:5_109:}
页:
[1]