| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- 프로그래밍언어
- 정처기
- 10172
- 개발
- 전공자
- 10171
- 프로그래밍
- 백준
- 코딩테스트
- 코딩
- 정보처리기사합격후기
- 정보처리기사실기
- 비전공자
- double
- 7008번
- 2588
- 정보처리기사
- float
- 곱셈
- 코테
- 알람시계
- 파이썬
- 2884
- 정처기필기
- 정처기실기
- precision
- 프로그래머스
- C
- 정보처리기사필기
- 합격후기
- Today
- Total
Like a Star
HackerRank Write a function 본문
Quiz.
An extra day is added to the calendar almost every four years as February 29, and the day is called a leap day. It corrects the calendar for the fact that our planet takes approximately 365.25 days to orbit the sun. A leap year contains a leap day.
In the Gregorian calendar, three conditions are used to identify leap years:
- The year can be evenly divided by 4, is a leap year, unless:
- The year can be evenly divided by 100, it is NOT a leap year, unless:
- The year is also evenly divisible by 400. Then it is a leap year.
- The year can be evenly divided by 100, it is NOT a leap year, unless:
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.
https://www.timeanddate.com/date/leapyear.html
Leap Day on February 29
Leap years have 366 instead of the usual 365 days. Is 2022 a leap year?
www.timeanddate.com
input Format. Read year, the year to test.
output Format.
The function must return a Boolean value (True/False).
Output is handled by the provided code stub.
ex.)
input
1990
output
False
우선, 이 문제를 이해하기 위해서는 '윤년'에 대한 이해가 필요하다.
아래 사이트는 이에 대한 설명이다.
https://namu.wiki/w/%EC%9C%A4%EB%85%84
그레고리안력으로 불리는 이것은, 1년이 365.2425일 이라고 계산하는 달력법이다.
이 달력법에 의하면 윤년은 다음과 같은 규칙을 갖는다.
- 4의 배수년은 윤년
- 100의 배수이면서 400의 배수면 평년
따라서 4의 배수가 아니거나, 400의 배수인 해는 평년, 나머지는 윤년이다.
이에 유의해서 소스를 작성하며 문제를 해결할 수 있다.
my code)
def is_leap(year):
leap = False
# Write your logic here
if year % 100 == 0:
if year % 400 == 0:
leap = True
else:
pass
elif year % 4 == 0:
leap = True
return leap
year = int(input())
print(is_leap(year))'PL > Python' 카테고리의 다른 글
| HackerRank Diagonal Difference (0) | 2022.08.08 |
|---|---|
| HackerRank Compare the Triplets (0) | 2022.08.05 |
| HackerRank Python If-Else (0) | 2022.08.05 |
| 백준 18108번 1998년생인 내가 태국에서는 2541년생?! (0) | 2022.08.03 |
| 백준 10869번 사칙연산 (0) | 2022.08.02 |