from datetime import datetime, timedelta
def menstrual_cycle_prediction(start_date, cycle_length):
start_date = datetime.strptime(start_date, "%Y-%m-%d")
next_period_date = start_date + timedelta(days=cycle_length)
return next_period_date
# 获取用户输入
start_date = input("请输入上一次月经的首日日期(YYYY-MM-DD):")
cycle_length = int(input("请输入月经周期的天数:"))
# 调用函数进行预测
next_period_date = menstrual_cycle_prediction(start_date, cycle_length)
# 计算危险期和安全期
ovulation_date = next_period_date - timedelta(days=14)
dangerous_period_start = ovulation_date - timedelta(days=5)
dangerous_period_end = ovulation_date + timedelta(days=4)
safe_period_start = (next_period_date - timedelta(days=14)).strftime("%Y-%m-%d")
safe_period_end = (next_period_date - timedelta(days=5)).strftime("%Y-%m-%d")
# 输出结果
print("下次月经来的日期是:",
用python做生理期预测的小工具
最新推荐文章于 2025-04-24 19:54:05 发布