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))
'software Engineering > (Python)HackerRank' 카테고리의 다른 글
[Python] HackerRank -List Comprehensions (0) | 2023.01.28 |
---|---|
[Python] HackerRank - Print Function (0) | 2023.01.27 |
[Python] HackerRank - Loops (0) | 2023.01.21 |
[Python] HackerRank - Python: Division (0) | 2023.01.20 |
[Python] HackerRank - Arithmetic Operators (0) | 2023.01.19 |