-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHackerrank: If-Else Question
45 lines (35 loc) · 1.18 KB
/
Hackerrank: If-Else Question
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Task
#Given an integer,n, perform the following conditional actions:
#If n is odd, print Weird
#If n is even and in the inclusive range of to , print Not Weird
#If n is even and in the inclusive range of to , print Weird
#If n is even and greater than , print Not Weird
#Input Format : A single line containing a positive integer, n
#Constraints : 1<=n<=100
#!/bin/python
import math
import os
import random
import re
import sys
if __name__ == '__main__':
n = int(raw_input().strip())
n = random.randint(1,100)
if n%2 == 0:
if n in range(2,6):
print('Not Weird')
elif n in range(6,21):
print('Weird')
elif n>20:
print('Not Weird')
else:
print('Weird')
# 틀린 답안
if __name__ == '__main__':
n = int(raw_input().strip())
#n = random.randint(1,100) 랜덤값을 줘버리면 안된다. 왜냐하면 range함수를 이용하여 이미 범위내 연속된 숫자를 주기 때문이다.
if n in range (6, 21) or n % 2 != 0: #odd number 홀수일 때는 n%2!=0 짝 even number 짝수일 때 n%2==0
print("Weird")
else:
print("Not Weird")
# 맞는 답안