Вот пример того, как можно создать программу с использованием модуля черепахи Python для рисования случайных звезд на ночном небе:
import turtle
import random
# Set up the turtle screen
screen = turtle.Screen()
screen.setup(800, 600)
screen.bgcolor("black")
# Create a turtle for drawing stars
star = turtle.Turtle()
star.shape("turtle")
star.color("white")
star.speed(0)
# Draw random stars
for _ in range(50):
# Generate random coordinates
x = random.randint(-400, 400)
y = random.randint(-300, 300)
size = random.randint(5, 20)
# Move the turtle to the random coordinates
star.penup()
star.goto(x, y)
star.pendown()
# Draw a star shape
for _ in range(5):
star.forward(size)
star.right(144)
# Hide the turtle
star.hideturtle()
# Keep the screen open until it is closed
turtle.done()
Эта программа использует модуль черепахи для создания черного фона и белой черепахи, рисующей звезды на экране. Он генерирует случайные координаты для каждой звезды и рисует форму звезды с помощью цикла.