“无输出”可能意味着窗口正在自动关闭。尝试将此添加到末尾以防止:
# ...
bob.hideturtle()
input('press enter to exit')
你可以通过传送到你想要绘制每个形状的地点,多次绘制相同的形状。
def shape():
for i in range(18):
bob.left(140)
bob.forward(100)
# coordinates of each of the shapes
# these are completely arbitrary
# you can change these to whatever (adjust spacing, change where they are, etc)
# you can also write this using ranges if you want
for x in (-100, 0, 100, 200):
for y in (-150, -50, 50, 150):
bob.penup()
bob.setposition(x, y)
bob.pendown()
shape()
这将循环通过所有16个点,
-100, -150
,
-100, -50
,
-100, 50
, ...,
200, 150
.
请注意,我将您的形状更改为仅循环18次-这使总旋转为360度的倍数,因此下一个形状不会倾斜。此外,该形状只有18条边,因此绘制额外的2条边将是一种浪费。
This is what would happen if it was left at 20.
输出: