# Authors:
# Date: 10/31/25
# Practicum 3, Part 1 (18 of 20 points)

"""
This file contains the instructions and skeleton code for Part 1 of Prac 3.
This part is broken into three subtasks; you are encouraged to implement them
in the order listed:
A. the days_in_month function (8 points)
B. the day_of_year function (6 points)
C. the main program which makes use of the above (4 points)

Each part has its own test file, e.g. prac1_part1A_test.py tests part A.

Overview: you'll implement a program that calculates 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 2025, while February 10th would be day 41 (31
days in January plus
10 days in Feburary).

NOTE: You may not import or use any date- or time-related modules.
"""

def days_in_month(year, month): # Part 1A, 8 points
    """ Return the number of days in the given month of the year, where
    1 is January, 2 is February, and so on. The number of days follows the
    rules:
     - April (4), June (6), September (9) 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
           (there are a few exceptions in reality, but we will simplify)
     - All the rest of the months have 31 days
    Precondition: month is between 1 and 12 (inclusive).
    Examples:
    >>> days_in_month(2025, 1) # January
    31
    >>> days_in_month(2024, 11) # November
    30
    >>> days_in_month(2024, 2) # Leap year February
    29
    """
    if month == 2:
        if year % 4 == 0: # leap year
            return 29
        else:
            return 28
    elif month == 4 or month == 6 or month == 9 or month == 11: # 30 days
        return 30
    else:
        return 31


def day_of_year(year, month, day): # Part 1B, 6 points
    """ 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.
    Example outputs:
    >>> day_of_year(2025, 3, 1)
    60
    >>> 
    >>> day_of_year(2025, 12, 31)
    365
    >>> day_of_year(2024, 12, 31)
    366"""
    
    days = 0
    for m in range(1, month):
        days += days_in_month(year, m)
    
    return days + day
    


# Part 1C, 4 points
""" Write a main program that takes three integer command line arguments
representing a year, month, and day. The program then prints the day of the
year (between 1 and 366). Be sure to put your main program inside a main guard.
"""
# Write your main program here

if __name__ == "__main__":    

    import sys
    year = int(sys.argv[1])
    month = int(sys.argv[2])
    day = int(sys.argv[3])

    print(day_of_year(year, month, day))
    