/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/python/lab-111-015/main.py
33 строки
888 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
import turtle import math def draw_star(n: int, radius: float, step: int = 2, fill: bool = False, color: str = "black"): """ Рисует звезду {n/step} по обозначению Шлефли. Требуется, чтобы gcd(n, step) == 1 и 2*step < n. """ if math.gcd(n, step) != 1 or 2 * step >= n: raise ValueError("Некорректные параметры: требуется gcd(n, step) == 1 и 2*step < n") t = turtle.Turtle() t.speed(0) t.color(color) if fill: t.begin_fill() angle = 360.0 / n t.penup() t.goto(radius, 0) t.setheading(90 + angle / 2) t.pendown() for _ in range(n): t.forward(radius * 2 * math.sin(math.radians(step * angle / 2))) t.left(step * angle) if fill: t.end_fill() t.hideturtle() draw_star(5, 100) turtle.done()