# centipede.py from turtle import * # show a centipede-like thing moving around the screen def centipede(length, step, life): # lift the pen so no drawing happens penup() theta = 0 dtheta = 1 for i in range(life): forward(step) left(theta) theta += dtheta # draw a picture of a turtle stamp() if i > length: clearstamps(1) if theta > 10 or theta < -10: dtheta = -dtheta if ycor() > 350: left(30) # draw a star on the screen def star(): color('red', 'yellow') begin_fill() hideturtle() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() def square(side): pendown() for i in range(4): forward(side) left(90) def triangle(side): pendown() for i in range(3): forward(side) left(120) def main(): setworldcoordinates(-400, -400, 400, 400) ask = input("Centipede (c) or star (s)? ") if ask == "c": centipede(14, 10, 200) elif ask == "s": star() elif ask == "q": square(50) else: triangle(50) exitonclick() main()