python_by_example/trtl/turtle09.py

30 lines
681 B
Python
Raw Permalink Normal View History

2023-11-11 00:09:22 -03:00
import turtle as tt
from random import randint, random
def turtle_09():
"""Draw a pattern that will change each time the program is run. Use the
random function to pick the number of lines, the length of each line and
the angle of each turn."""
def rand_lines():
return randint(50, 150)
def rand_length():
return randint(150, 300)
def rand_angl():
return round(random()*360, 2)
lines = rand_lines()
length = rand_length()
angle = rand_angl()
tt.speed(100)
tt.bgcolor("black")
tt.color("magenta")
for _ in range(lines):
tt.left(angle)
tt.forward(length)
tt.exitonclick()