from datetime import datetime, timedelta
def calculate_due_date(last_period_date):
Calculates the estimated due date of pregnancy based on the last period date.
Args:
last_period_date (str): Last period date in the format 'YYYY-MM-DD'.
Returns:
str: Estimated
due date in the format 'YYYY-MM-DD'.
"""
last_period =
datetime.strptime(last_period_date, "%Y-%m-%d")
due_date = last_period + timedelta(days=280) # Assuming a 280-day average pregnancy
return due_date.strftime("%Y-%m-%d")
# Example usage
last_period_date = "2023-01-15" # Last period date
estimated_due_date = calculate_due_date(last_period_date)
print(f"The estimated due date is:
{estimated_due_date}")
This script defines a function calculate_due_date() that takes the last period date as input and calculates the estimated due date of pregnancy. It assumes a 280-day average pregnancy duration and adds 280 days to the last period date to calculate the due date.
In the example usage section, the script demonstrates how to use the function by providing a sample last period date. It then prints the estimated due date.
You can modify the last_period_date variable to calculate the estimated due date based on different last period dates.