+ 2

if i input 6 it give weird and if i input 20 it give not weird .why it include 6 in 1st case not 20 in another case

n = int(input()) if(n%2!=0): print("Weird") else: if n in range(1,6): print("Not Weird") elif n in range(7,20): print("Weird") else: print("Not Weird")

3rd Apr 2018, 7:07 AM
Bahubali
Bahubali - avatar
4 Answers
+ 12
n = int(input()) if(n%2!=0): #for odd print("Weird1") else: if n in range(1,6): #1,2,3,4,5 print("Not Weird1") elif n in range(7,20): #7,8,9,10,...19 print("Weird2") else: print("Not Weird2") #👉for 6,20 #so output will be "Now Weird2" for both 6,20
3rd Apr 2018, 7:13 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 9
â˜ș //welcome 👍
3rd Apr 2018, 7:42 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
thank u bhai
3rd Apr 2018, 7:40 AM
Bahubali
Bahubali - avatar
+ 1
range(1,6) starts from 1 to 5 range(7, 20) starts from 7 to 19 so 6 and 20 trigger the else part of the code print("Not Weird")
3rd Apr 2018, 11:10 AM
Loïc Mahé
Loïc Mahé - avatar