Season from a month

EasyIf-Else Programs · 38 of 64

Write a Python program that reads a month name and prints its season (Indian seasons: Winter Dec-Feb, Summer Mar-May, Monsoon Jun-Sep, Post-monsoon Oct-Nov).

Advertisement
Input
"February", "May", "August", "October"
Output
February -> Winter
May -> Summer
August -> Monsoon
October -> Post-monsoon

Approach

  1. Check which group of months contains the input.

Solution

Python
def season(month):    month = month.capitalize()    if month in ("December", "January", "February"):        return "Winter"    elif month in ("March", "April", "May"):        return "Summer"    elif month in ("June", "July", "August", "September"):        return "Monsoon"    elif month in ("October", "November"):        return "Post-monsoon"    return "Unknown month" for m in ["February", "May", "August", "October"]:    print(m, "->", season(m))
Output
February -> Winter
May -> Summer
August -> Monsoon
October -> Post-monsoon

Line by line

Lines 3-10

Each elif checks one season’s months.

Line 11

A final return covers anything that matched no season.

Note

The original sample said February is Summer. Season boundaries vary by country; this solution uses the common Indian classification with February in Winter.

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs

Leave a Comment