Hanwool Codes RSS Tag Admin Write Guestbook
2023-01-26 06:11:27

Write a function | HackerRank

 

Write a function | HackerRank

Write a function to check if the given year is leap or not

www.hackerrank.com

 

Goal

 

This task is to return true if a give year is a leap year, otherwise return false

 

 

Solution

 

There are three main conditions to check leap year:

1. It can be evenly divided by 4 - leap year

2. It can be evenly divided by 100, it is NOT a leap year, unless it is evenly disivible by 400 - leap year

3. Otherwise it is not a leap year.

 

These conditions can be shown in this code.

# Write a function

def is_leap(year):
    leap = False
    
    # Write your logic here
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                leap = True
            else : 
                leap = False
        else:  
            leap = True
        
    else:
        leap = False
    
    return leap

year = int(input())
print(is_leap(year))
Hanwool Codes. Designed by 코딩재개발.