28 lines
586 B
Python
28 lines
586 B
Python
import turtle as tt
|
|
from random import choice
|
|
|
|
def turtle_07():
|
|
"""Draw an octagon that uses a different colour (randomly selected from a
|
|
list of six possible colours) for each line."""
|
|
colors = ['yellow', 'orange', 'red', 'green', 'magenta']
|
|
|
|
def rand_color():
|
|
return choice(colors)
|
|
|
|
tt.bgcolor("black")
|
|
tt.pensize(10)
|
|
tt.speed(2)
|
|
tt.up()
|
|
tt.back(100)
|
|
tt.left(90)
|
|
tt.forward(250)
|
|
tt.right(90)
|
|
tt.down()
|
|
|
|
for _ in range(8):
|
|
tt.color(rand_color())
|
|
tt.forward(200)
|
|
tt.right(45)
|
|
|
|
tt.exitonclick()
|