The program is an illustration of conditional statements.
Conditional statements are statements whose execution is dependent on its truth value.
The program in Python where comments are used to explain each line is as follows:
#This initializes a list of months
mnths = ["january","february","march","april","may","june","july","august","september","october","november","december"]
#This gets input for days
days = int(input("Day: "))
#This gets input for months
month = input("Month: ")
#This checks if the input month is present in the list of months.
if not(month.lower() in mnths):
#Print invalid, if not
print("Invalid")
#If yes,
else:
#This reads the month index, from the list where 0 - January 11 - December
month_index = mnths.index(month.lower())
#For January
if month_index == 0:
#If days is not between 1 and 31 (inclusive), then the date is invalid
if days<1 or days>31: print("Invalid")
#else, all days in January are winter
else: print("Winter")
#For February
elif month_index == 1:
#If days is not between 1 and 28 (inclusive), then the date is invalid
if days<1 or days>28: print("Invalid")
#else, all days in February are winter
else: print("Winter")
#For March
elif month_index == 2:
#If days is not between 1 and 31 (inclusive), then the date is invalid
if days<1 or days>31: print("Invalid")
#Days less than 20 are Winter
elif days<= 19: print("Winter")
#Others are spring
else: print("Spring")
#For April
elif month_index == 3:
#If days is not between 1 and 30 (inclusive), then the date is invalid
if days<1 or days>30: print("Invalid")
#else, all days in April are winter
else: print("Spring")
#For May
elif month_index == 4:
#If days is not between 1 and 31 (inclusive), then the date is invalid
if days<1 or days>31: print("Invalid")
#else, all days in May are winter
else: print("Spring")
#For June
elif month_index == 5:
#If days is not between 1 and 30 (inclusive), then the date is invalid
if days<1 or days>30: print("Invalid")
#Days less than 21 are Spring
elif days<= 20: print("Spring")
#Others are summer
else: print("Summer")
#For July
elif month_index == 6:
#If days is not between 1 and 31 (inclusive), then the date is invalid
if days<1 or days>31: print("Invalid")
#else, all days in July are summer
else: print("Summer")
#For August
elif month_index == 7:
#If days is not between 1 and 31 (inclusive), then the date is invalid
if days<1 or days>31: print("Invalid")
#else, all day in August are Summer
else: print("Summer")
#For September
elif month_index == 8:
#If days is not between 1 and 31 (inclusive), then the date is invalid
if days<1 or days>31: print("Invalid")
#Days less than 22 are Summer
elif days<= 21: print("Summer")
#Others are Autumn
else: print("Autumn")
#For October
elif month_index == 9:
#If days is not between 1 and 31 (inclusive), then the date is invalid
if days<1 or days>31: print("Invalid")
#All days in October are Autumn
else: print("Autumn")
#For November
elif month_index == 10:
#If days is not between 1 and 30 (inclusive), then the date is invalid
if days<1 or days>30: print("Invalid")
#Else, all days are Autumn
else: print("Autumn")
#For December
elif month_index == 11:
#If days is not between 1 and 31 (inclusive), then the date is invalid
if days<1 or days>31: print("Invalid")
#Days less than 21 are Autumn
elif days<21: print("Autumn")
#Others are Winter
else: print("Winter")
Read more about similar programs at:
link