Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime, timedelta
- def calculate_dates(last_period_date, period_length, cycle_length):
- # Calculate the next period date
- next_period_date = last_period_date + timedelta(days=cycle_length)
- # Period end date
- period_end_date = last_period_date + timedelta(days=period_length)
- # The fertile window starts 3 to 5 days after the period ends and lasts for about 6 days.
- # We'll calculate the start and end dates of this ovulation period.
- ovulation_start_date = period_end_date + timedelta(days=3) # Start of the fertile window
- ovulation_end_date = period_end_date + timedelta(days=5) + timedelta(days=6) # End of the fertile window
- return next_period_date, ovulation_start_date, ovulation_end_date
- def get_date_input(prompt):
- while True:
- date_str = input(prompt)
- try:
- # Try to convert the input string to a datetime object
- return datetime.strptime(date_str, "%Y-%m-%d")
- except ValueError:
- # If input is not a valid date, prompt the user to enter a new value
- print("Invalid date format. Please enter the date in YYYY-MM-DD format.")
- def get_integer_input(prompt):
- while True:
- try:
- # Try to convert the input to an integer
- return int(input(prompt))
- except ValueError:
- # If input is not an integer, prompt the user to enter a new value
- print("Invalid input. Please enter a valid number.")
- # Get user inputs
- print("Please enter the following information:")
- last_period_date = get_date_input("Last period start date (YYYY-MM-DD): ")
- period_length = get_integer_input("How many days does the period last?: ")
- cycle_length = get_integer_input("What is the cycle length in days (from the start of one period to the start of the next)?: ")
- # Calculate the next period and ovulation dates
- next_period, ovulation_start, ovulation_end = calculate_dates(last_period_date, period_length, cycle_length)
- # Print the results
- print("\nNext Period Start Date:", next_period.strftime("%Y-%m-%d"))
- print("Estimated Ovulation Period: From", ovulation_start.strftime("%Y-%m-%d"), "to", ovulation_end.strftime("%Y-%m-%d"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement