본문 바로가기
코딩 공부방 👩‍💻👨‍💻/알고리즘

[Python] 해커랭크(HackerRank) : Python If-Else

by ByJinnie 2023. 2. 13.
반응형

[문제] 

If-Else문을 연습하는 문제입니다. 1 이상 100 이하의 짝수를 입력해야 합니다.

홀수가 입력되면 Weird가 출력돼야 합니다.

2 이상 5 이하의 짝수, 20 초과의 짝수가 입력되면 Not Weird가 출력돼야 합니다.

하지만 입력된 짝수가 6 이상 20이하일 경우, Weird가 출력돼야 합니다.

 

예시)

입력값 :

 3

24

 

출력값:

Weird

Not Weird

 

[코드]

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input().strip())
    if n % 2 != 0 :
        print("Weird")
    elif (n % 2 == 0):
        if n >= 2 and n <= 5:
            print("Not Weird")
        elif n >= 6 and n <= 20:
            print("Weird")
        elif n > 20:
            print("Not Weird")

 

* 문제 출처 (Prepare > Python > Introduction > Python If-Else)

: https://www.hackerrank.com/

 

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

 

반응형

댓글