본문 바로가기

알고리즘/해커랭크

Python If-Else Discussions

문제

홀수일때 Weird 출력

20이상이거나 2~5사이의 짝수는 Not Weird 출력

6~20사이의 짝수는 Weird 출력

 

제출한 코드

 n = int(input().strip())

    if n%2 == 0 and (n>20 or n<5):
        print("Not Weird")
    else:
        print("Weird")

 

다른사람 코드

n = int(input().strip())
check = {True: "Not Weird", False: "Weird"}

print(check[
        n%2==0 and (
            n in range(2,6) or 
            n > 20)
    ])

이렇게도 활용하는구나ㅋㅋ 재밌다 ㅎ

'알고리즘 > 해커랭크' 카테고리의 다른 글

Kangaroo  (0) 2020.03.06
Apple and Orange  (0) 2020.03.06
Grading Students (python3)  (0) 2020.02.29
Loops (python3)  (0) 2020.02.27
Birthday Cake Candles(python3)  (0) 2020.02.26