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).
Input
"February", "May", "August", "October"
Output
February -> Winter
May -> Summer
August -> Monsoon
October -> Post-monsoon
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.
Write a Python program that prints “FizzBuzz” for multiples of both 2 and 3, “Fizz” for multiples of 2 and “Buzz” for multiples of 3; otherwise print the number.
Input
14, 9, 6, 7
Output
14 Fizz
9 Buzz
6 FizzBuzz
7 7
Approach
Test the combined case first, then each single case.
Write a Python program to check whether a year is a leap year.
Input
2000, 1900, 2024
Output
2000 is a leap year
1900 is not a leap year
2024 is a leap year
Approach
Divisible by 400: leap. Else divisible by 100: not leap. Else divisible by 4: leap.
Solution
Python
foryearin[2000,1900,2024]:ifyear%400==0:print(year,"is a leap year")elifyear%100==0:print(year,"is not a leap year")elifyear%4==0:print(year,"is a leap year")else:print(year,"is not a leap year")
Output
2000 is a leap year
1900 is not a leap year
2024 is a leap year
Line by line
Lines 2-7
The rules are checked from the most specific (400) to the most general (4), which is why the order matters.
Learn the concept
New to this topic? Read the lesson, then come back.