Как циклически перемещаться по дням, используя модуль в Python

Метод 1: использование по модулю с увеличивающимся счетчиком

days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
current_day = "Monday"
num_days_to_cycle = 10
# Get the index of the current day
current_day_index = days.index(current_day)
# Calculate the index of the new day after cycling
new_day_index = (current_day_index + num_days_to_cycle) % len(days)
# Get the new day based on the index
new_day = days[new_day_index]
print(new_day)  # Output: Thursday

Метод 2: использование модуля с числовым представлением дней

days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
current_day = "Monday"
num_days_to_cycle = 10
# Get the numeric representation of the current day
current_day_num = days.index(current_day)
# Calculate the numeric representation of the new day after cycling
new_day_num = (current_day_num + num_days_to_cycle) % len(days)
# Get the new day based on the numeric representation
new_day = days[new_day_num]
print(new_day)  # Output: Thursday

Метод 3: использование Modulo с объектами datetime

import datetime
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
current_day = "Monday"
num_days_to_cycle = 10
# Get the index of the current day
current_day_index = days.index(current_day)
# Create a datetime object for the current day
current_date = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
current_date += datetime.timedelta(days=current_day_index)
# Calculate the new date after cycling
new_date = current_date + datetime.timedelta(days=num_days_to_cycle)
new_day_index = new_date.weekday()
# Get the new day based on the index
new_day = days[new_day_index]
print(new_day)  # Output: Thursday