Example
Input
2016
Output
Leap year
Required to Know
Use of Variables, Use of different operators like assignment or arithmetic operators, Use of functions like print(), and input(), Use of If-else, and Use of Data types.
Steps
Take the year as input from the user.
The condition of the leap year will go in this format: -
If the year is divisible by 4 and not 100 then it is not a leap year.
Similarly, if the year is divisible by 400 then it is a leap year.
Program
# This code checks if a year is a leap year.
# Get the year from the user.
year = int(input("Enter the year: "))
# Check if the year is divisible by 4.
if year % 4 == 0:
# If the year is divisible by 4, it is a leap year unless it is divisible by 100.
if year % 100 != 0:
# If the year is not divisible by 100, it is a leap year.
print("Leap year")
else:
# If the year is divisible by 100, it is not a leap year unless it is divisible by 400.
if year % 400 == 0:
# If the year is divisible by 400, it is a leap year.
print("Leap year")
else:
# If the year is not divisible by 400, it is not a leap year.
print("Not a leap year")
else:
# If the year is not divisible by 4, it is not a leap year.
print("Not a leap year")