[백준/파이썬] 10480번 풀이

업데이트:



문제 정보


풀이

문제

Some numbers are just, well, odd. For example, the number 3 is odd, because it is not a multiple of two. Numbers that are a multiple of two are not odd, they are even. More precisely, if a number n can be expressed as n = 2 ∗ k for some integer k, then n is even. For example, 6 = 2 ∗ 3 is even.

Some people get confused about whether numbers are odd or even. To see a common example, do an internet search for the query “is zero even or odd?” (Don’t search for this now! You have a problem to solve!)

Write a program to help these confused people.

입력 요약
Input begins with an integer 1 ≤ n ≤ 20 on a line by itself, indicating the number of test cases that follow. Each of the following n lines contain a test case consisting of a single integer −10 ≤ x ≤ 10.

출력 요약
For each x, print either ‘x is odd’ or ‘x is even’ depending on whether x is odd or even.

코드

for i in range(int(input())):
    n=int(input())
    print(f'{n} is {"odd"if n%2!=0 else"even"}')

설명

핵심은 구현 관점에서 Some numbers are just, well, odd. For example, the number 3 is odd, because it is not a multiple of two. …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



이런 주제는 어떠신가요?

비슷한 난이도와 유형의 문제를 이어서 보면 풀이 감각을 더 빠르게 잡기 좋습니다.

댓글남기기