帮你用chatgpt滚了一圈
[Python] 纯文本查看 复制代码 from datetime import datetime, timedelta
def generate_training_plan(start_date, project):
# 建立一个训练项目列表
project_list = ['胸', '背', '腿']
# 建立一个训练类型列表
type_list = ['胸', '背', '腿', '有氧', '休息']
# 计算起始日期之后30天的日期
end_date = start_date + timedelta(days=30)
# 初始化当前训练类型和训练天数
current_type = project
days_since_last_rest = 0
# 生成训练计划
training_plan = []
while start_date <= end_date:
training_plan.append((start_date, current_type))
# 每个训练项目完成后,切换到下一个训练项目
current_type_index = type_list.index(current_type)
next_type_index = (current_type_index + 1) % len(project_list)
next_type = project_list[next_type_index]
# 检查是否需要进行有氧训练或休息
days_since_last_rest += 1
if current_type in project_list and days_since_last_rest == 3:
current_type = '休息'
days_since_last_rest = 0
elif current_type == '休息':
current_type = '有氧'
else:
current_type = next_type
# 增加一天
start_date += timedelta(days=1)
return training_plan
[Python] 纯文本查看 复制代码 start_date = datetime(2023, 1, 1)
project = '胸'
training_plan = generate_training_plan(start_date, project)
for training_day in training_plan:
print(training_day[0].strftime('%Y-%m-%d'), training_day[1])
[Python] 纯文本查看 复制代码 from datetime import datetime, timedelta
# 定义每个训练周期的类型
TRAINING_TYPES = ["胸", "背", "腿", "有氧", "休息"]
def generate_training_plan(start_date, start_training_type, day_before_yesterday_type, yesterday_type):
# 将起始日期和前两天的项目转换为datetime对象
start_date = datetime.strptime(start_date, "%Y-%m-%d")
day_before_yesterday_type_index = TRAINING_TYPES.index(day_before_yesterday_type)
yesterday_type_index = TRAINING_TYPES.index(yesterday_type)
# 定义一个列表,用于存储每天的训练类型
training_plan = []
# 根据起始日的类型确定第一天的训练类型
if start_training_type == "有氧" or start_training_type == "休息":
training_type_index = TRAINING_TYPES.index(start_training_type)
else:
training_type_index = (yesterday_type_index + 1) % 3
# 生成未来30天的训练计划
for i in range(30):
# 将当天的训练类型加入训练计划中
training_plan.append((start_date + timedelta(days=i)).strftime("%Y-%m-%d") + " " + TRAINING_TYPES[training_type_index])
# 根据当天的训练类型确定下一天的训练类型
if TRAINING_TYPES[training_type_index] == "胸" or TRAINING_TYPES[training_type_index] == "背" or TRAINING_TYPES[training_type_index] == "腿":
if i % 3 == 2:
training_type_index = (training_type_index + 2) % 5
else:
training_type_index = (training_type_index + 1) % 5
else:
training_type_index = (training_type_index + 1) % 5
return training_plan
|