규도자 개발 블로그
[해커랭크(Hackerrank)/30 Days of Code/파이썬3(python3)] Day 3: Intro to Conditional Statements 본문
알고리즘/풀이
[해커랭크(Hackerrank)/30 Days of Code/파이썬3(python3)] Day 3: Intro to Conditional Statements
규도자 (gyudoza) 2019. 3. 21. 20:42Objective
In this challenge, we're getting started with conditional statements. Check out the Tutorial tab for learning materials and an instructional video!
Task
Given an integer, , perform the following conditional actions:
- If is odd, print
Weird
- If is even and in the inclusive range of to , print
Not Weird
- If is even and in the inclusive range of to , print
Weird
- If is even and greater than , print
Not Weird
Complete the stub code provided in your editor to print whether or not is weird.
Input Format
A single line containing a positive integer, .
Constraints
Output Format
Print Weird
if the number is weird; otherwise, print Not Weird
.
Sample Input 0
3
Sample Output 0
Weird
Sample Input 1
24
Sample Output 1
Not Weird
Explanation
Sample Case 0:
is odd and odd numbers are weird, so we print Weird
.
Sample Case 1:
and is even, so it isn't weird. Thus, we print Not Weird
.
풀이
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
N = int(input())
result = 'Weird'
if not N % 2 == 0:
result = 'Weird'
elif N % 2 == 0 and 2 <= N <= 5:
result = 'Not Weird'
elif N % 2 == 0 and 6 <= N <= 20:
result = 'Weird'
elif 20 < N:
result = 'Not Weird'
print(result)
설명
조건문을 통해 Weird 혹은 Not Weird를 출력하는 문제이다.
'알고리즘 > 풀이' 카테고리의 다른 글
Comments