python 海龟中的左中和右中

Left center and right center in python turtle

我正在尝试按照所附图片对齐我的方块。我尝试了很多事情,但我无法这样做。

这是我目前所拥有的

print(turtle.pos())
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.exitonclick() 

刚开始使用turtle,看了网上的教程,还是没能实现。

如果您将 right 更改为 left,它将打印您想要的图像。

您可能需要先设置 heading(90),具体取决于您的海龟开始的方向。

开始
turtle.setheading(180)

那么您的代码将正确绘制小方块。画完小方块后,插入

turtle.right(180)

在绘制大正方形之前,您的代码将起作用。