⚡ Минимальный пример
def custom_range(start, stop, step=1):
while start < stop:
yield start
start += step
Пример 1. custom_range
def custom_range(start, stop, step=1):
while start < stop:
yield start
start += step
for num in custom_range(2, 10, 2):
print(num) # 2 4 6 8
Пример 2. Случайные даты
import random
def is_leap(year: int) -> bool:
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
def random_dates(year: int):
days_in_month = {
1: 31, 2: 29 if is_leap(year) else 28, 3: 31,
4: 30, 5: 31, 6: 30, 7: 31, 8: 31,
9: 30, 10: 31, 11: 30, 12: 31
}
while True:
month = random.randint(1, 12)
day = random.randint(1, days_in_month[month])
yield f"{year}-{month:02d}-{day:02d}"
date_gen = random_dates(2025)
for _ in range(5):
print(next(date_gen))