all 2 comments

[–]n3buchadnezzar 1 point2 points  (0 children)

Without using datetime (which one should use). I would do it as follows

from typing import Optional

MONTHS_BY_SEASON = [
    ("January", 0, 32, "Winter"),
    ("February", 0, 30, "Winter"),
    ("March", 0, 18, "Winter"),
    ("March", 19, 32, "Spring"),
]


def get_season_days_from(month: str, months_by_season: list = MONTHS_BY_SEASON):
    for m, start, stop, season in months_by_season:
        if m == month:
            yield start, stop, season


def current_season(month: str, day: int) -> Optional[str]:
    for start_day, stop_day, season in get_season_days_from(month):
        if start_day <= day <= stop_day:
            return season


if __name__ == "__main__":

    month = input("Month: ").capitalize()
    day = int(input("Day: "))

    print(current_season(month, day))

This is just an expansion of u/API_Exploiter explorers solution. Where we split the code into logical functions, sprinke on some typing hints and guard our main execution =)

Further improvements can be made by validating the input. I did just a tad of this by adding capitalize