top of page
Click here to go to the home page of AskTheCode.

Write a function to check leap year - AskTheCode

Team ATC

Updated: Mar 12, 2021

Python program to check a year is leap or not | Python programming | Ask The Code

 

Problem:

Given a year, determine whether it is a leap year. If it is a leap year, return the Boolean True, otherwise return False. Note that the code stub provided reads from STDIN and passes arguments to the is leap function. It is only necessary to complete the is leap function.


Input:

Read year, the year to test.

Output:

The function must return a Boolean value (True/False). Output is handled by the provided code stub.

Sample input:

1990


Sample output:

False

 

Code:

def is_leap(year):
    leap = False
    if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
        leap = True
    
    return leap

year = int(input())
print(is_leap(year))

Recent Posts

See All

コメント


bottom of page