我目前正在上初级编程课程,并且正在完成作业。现在,我必须用模块 turtle 制作 3 个房子(我完成了):
def drawBody(mover):
#Rectangle part
mover.fillcolor("blue")
mover.begin_fill()
for i in range(2):
mover.forward(100)
mover.right(90)
mover.forward(75)
mover.right(90)
mover.end_fill()
#Triangle part
mover.fillcolor("red")
mover.begin_fill()
mover.left(45)
for i in range(2):
mover.forward(70.5)
mover.right(90)
mover.right(45)
mover.forward(100)
mover.end_fill()
#Create preproduction turtle
import turtle
wn = turtle.Screen()
josh = turtle.Turtle()
pointGoTo = -175
for houses in range(3):
josh.penup()
josh.goto(pointGoTo,0)
josh.pendown()
drawBody(josh)
josh.right(180)
pointGoTo = pointGoTo + 125
wn.exitonclick()
这是while代码。所以我想让乌龟停在某个点,红色方块的左上角。我已经尝试了多个点,但只是没有中断/停止。我的语法关闭了吗?还是我在接近整条房子的时候都错了?如果我含糊不清,请问您不明白什么,我真的很想弄清楚这一点,但是我一无所知。:
def drawBody(mover):
#Rectangle part
mover.fillcolor("blue")
mover.begin_fill()
for i in range(2):
mover.forward(100)
mover.right(90)
mover.forward(75)
mover.right(90)
mover.end_fill()
#Triangle part
mover.fillcolor("red")
mover.begin_fill()
mover.left(45)
for i in range(2):
mover.forward(70.5)
mover.right(90)
mover.right(45)
mover.forward(100)
mover.end_fill()
mover.left(90)
mover.forward(75)
mover.left(90)
n = mover.position()
print(n)
while True:
mover.forward(100)
n = mover.position()
print(n)
mover.left(90)
mover.forward(5)
mover.left(90)
n = mover.position()
print(n)
mover.forward(100)
mover.right(90)
mover.forward(5)
mover.right(90)
if n == (-75.30,0.00):
break
#Create preproduction turtle
import turtle
wn = turtle.Screen()
josh = turtle.Turtle()
pointGoTo = -175
for houses in range(3):
josh.penup()
josh.goto(pointGoTo,0)
josh.pendown()
drawBody(josh)
josh.right(180)
pointGoTo = pointGoTo + 125
wn.exitonclick()