Answer :-
here's a Python program that takes a date as input and outputs the date's season:
def get_season(month, day):
# Dictionary to map months to their corresponding season
seasons = {
'spring': [(3, 20), (6, 20)],
'summer': [(6, 21), (9, 21)],
'autumn': [(9, 22), (12, 20)],
'winter': [(12, 21), (3, 19)]
}
# Check if the month is valid
if month not in seasons:
return "invalid"
# Check if the day is valid
if not (1 <= day <= 31):
return "invalid"
# Get the corresponding season for the input date
for season, (start_month, start_day), (end_month, end_day) in seasons.items():
if (month == start_month and day >= start_day) or (month == end_month and day <= end_day):
return season
return "invalid"
# Input date (month as a string and day as an integer)
input_month = input("Enter the month: ").lower()
input_day = int(input("Enter the day: "))
# Get the season for the input date
result = get_season(input_month, input_day)
print(result)
↪ You can run this program and enter a month and day, and it will output the corresponding season or "invalid" if the input is not valid.