How to Check Leap Year using Python?


Leap year comes after every four years. For normal year, if it is divisible by four, it is called leap year, whereas for century year, it should be divisible by 400. The following Python program shows whether the year is leap or not

Example

yr=int(input('enter year'))
if yr%100==0: #century year
if yr%400==0:
   print ('{} is leap year'.format(yr))
else:
   print ('{} is not leap year'.format(yr))
else:
   if yr%4==0:
      print ('{} is leap year'.format(yr))
else:
   print ('{} is not leap year'.format(yr))

Output

enter year2012
2012 is leap year

enter year2018
2018 is not leap year

2000 is leap year

enter year1900
1900 is not leap year

Updated on: 22-Dec-2020

595 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements