(If-elif-else Control Flow)
Problem Statement
Check if a year is a leap year.
As per the Gregorian calendar (in 1582), the following rule is used to determine the kind of year:
- If the year number isn’t divisible by four, it’s a common year.
- Otherwise, if the year number isn’t divisible by 100, it’s a leap year.
- Otherwise, if the year number isn’t divisible by 400, it’s a common year.
- Otherwise, it’s a leap year.
The task is to determine if the given year is a leap year or not.
Output messages:
“Leap year.” if the year is a leap year.
“Common year.” if the year is common.
“Not within the Gregorian era.” If the year falls out of the Gregorian era.
Test Data:
Input: 2000
Output: Leap year.
Input: 1999
Output: Common year.
Input: 1996
Output: Leap year.
Input: 1500
Output: Not within the Gregorian era.
Solution:
year = int(input("Enter a year: "))## Write your code here.# if year > 1582: if (year%4 == 0 and year%100 != 100) or year%400 == 400: print("Leap year.") else: print("Common year.")else: print("Not within the Gregorian era.")
Output:




