# Author:
# Date: 5/9/25
# Exam 2, Problem 1 (9 out of 20 points)
""" In this program, you'll implement a function to calculate the day of the
year (between 1 and 366) given the year, month, and day. For example, January
1st, 2025 would be day 1 of the year 2024, while February 10th would be day
41 (31 days in January plus 10 days in Feburary).

NOTE: you may not import any date- or time-related modules for this problem.

The implementation is broken into two functions:
 - days_in_month returns the number of days in a given month, which may
   depend on the year.
     - September (9), April (4), and June (6), and November (11) have 30 days
     - February has 28 days in a non-leap year and 29 in a leap year. Leap
       years are those years divisible by 4 (this differs from reality in a
       a few cases, but we will make this simplification).
     - All the rest have 31 days
     
 - day_of_year takes a year, month, and day and returns the day of the year
   as described above. You are encouraged to use the days_in_month function
   in your implementation of day_of_year.
   
There is no main program required; you only need to implement the two
functions. If you do write a main program for testing purposes, put the main
program code inside a main guard.

Example outputs for days_in_month:
>>> days_in_month(2025, 1)
31
>>> days_in_month(2024, 11)
30
>>> days_in_month(2024, 2)
29

Example outputs for day_of_year:
>>> day_of_year(2025, 3, 1)
60
>>> 
>>> day_of_year(2025, 12, 31)
365
>>> day_of_year(2024, 12, 31)
366

Write your code below:
"""

def days_in_month(year, month):
    """ Return the number of days in the given month of the year, where
    1 is January, 2 is February, and so on.
    Precondition: month is between 1 and 12 (inclusive). """
    
    
    # implement this function
    if month == 9 or month == 4 or month == 6 or month == 11:
        return 30
    elif month == 2:
        if year % 4 == 0:
            return 29
        else:
            return 28
    else:
        return 31
    
    
def day_of_year(year, month, day):
    """ Return the day of the year on the given year/month/day date. For
    example, January 1st 2025 is day 1, while February 1st, 2025 is day 32.
    Precondition: the given year, month, and day form a valid date."""

    # implement this function
    total = 0
    for m in range(1, month):
        total += days_in_month(year, m)
    
    total += day
    
    return total
