Dremendo Tag Line

Check leap year in Python

if else - Question 4

In this question, we will see how to check if a year is a leap year or not in Python programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q4) Write a program in Python to input a year and check if it is a leap year or not. A leap year is a year which is either divisible by 400 or it is not divisible by 100 but divisible by 4. Make use of logical operators (and, or) to solve this question.


y=int(input('Enter a year '))

if y%400==0 or (y%100!=0 and y%4==0):
    print('Leap year')
    print('Not leap year')


Enter a year 2020
Leap year