Finding Leap Year or Not By Using Python Program
In this program, we first take input from the user for the year they want to check. We then check if the year is divisible by 4 using the modulus operator %. If it is, we check if the year is divisible by 100. If it is, we check if the year is divisible by 400. If it is, we print that the year is a leap year. If it's not divisible by 400, we print that the year is not a leap year. If the year is not divisible by 100, we print that the year is a leap year. If the year is not divisible by 4, we print that the year is not a leap year.
Input Program :
year = int(input("Enter a year: "))
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print(year, "is a leap year")
else:
print(year, "is not a leap year")
else:
print(year, "is a leap year")
else:
print(year, "is not a leap year")
Output Program :
Enter a year: 2020
2020 is a leap year,
alternately,
Enter a year: 2017
2017 is not a leap year