How to Check Leap Year using Python?

PythonServer Side ProgrammingProgramming

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

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))

Sample 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
raja
Published on 02-Dec-2020 14:21:03
Advertisements