반응형
[문제]
function과 조건문을 연습하는 문제입니다. year(연도)가 입력되면, 그 연도가 leap year인지 판별해야 합니다.leap year 조건은 문제에 나와있으며, 하기와 같습니다. def를 이용해 별도의 function(boolean)을 만들어야 합니다.* leap year의 조건: 4의 배수이되, 100의 배수는 될 수 없습니다.(다만 400의 배수일 경우, leap year에 해당됩니다.)
예시)
입력값 :
1990
출력값:
False
[코드]
def is_leap(year):
leap = False
if year % 4 == 0 and year % 100 != 0:
leap = True
elif year % 400 == 0:
leap = True
return leap
year = int(input())
print(is_leap(year))
* 문제 출처 (Prepare > Python > Introduction > Write a function)
HackerRank
HackerRank is the market-leading technical assessment and remote interview solution for hiring developers. Learn how to hire technical talent from anywhere!
www.hackerrank.com
반응형
'코딩 공부방 👩💻👨💻 > 알고리즘' 카테고리의 다른 글
[Python] 해커랭크(HackerRank) : List Comprehensions (0) | 2023.02.19 |
---|---|
[Python] 해커랭크(HackerRank) : Print Function (0) | 2023.02.18 |
[Python] 해커랭크(HackerRank) : Loops (0) | 2023.02.16 |
[Python] 해커랭크(HackerRank) : Python: Division (0) | 2023.02.15 |
[Python] 해커랭크(HackerRank) : Arithmetic Operators (0) | 2023.02.14 |
댓글