Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (16.4k points)

I'm attempting to make a basic program to decide if a specific year is a leap year. 

By definition, a leap year is actually divisible by four, yet not by 100, except if it is divisible by 400. 

Here is my code:

def leapyr(n):

    if n%4==0 and n%100!=0:

        if n%400==0:

            print(n, "is a leap year.")

    elif n%4!=0:

        print(n, "is not a leap year.")



At the point when I attempt this inside the Python IDLE, the module returns None back. I'm almost certain that I ought to get

1900 is a leap year

1 Answer

0 votes
by (26.4k points)

You can try using calendar.isleap :

import calendar


Looking for a good python tutorial course? Join the python certification course and get certified.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
4 answers

Browse Categories