The problem is like this
My solution:
n= int(input())
if n%2==0:
if (n >=2 & n<=5):
print("Not Weird")
elif n >=6 & n<=20:
print("Weird")
else:
print ("Not Weired")
else:
print ("Weird")
Now, if I enter 18 then it should be printed "Weird". But it is showing "Not Weird".
I am not getting where the problem of my code is.
Advertisement
Answer
The operator & is the bitwise and operation.
You need logical AND, instead, and it is done by means of and keyword.
Just replace & with and:
n= int(input())
if n%2==0:
if (n >=2 and n<=5): #modified here!
print("Not Weird")
elif n >=6 and n<=20: #modified here!
print("Weird")
else:
print ("Not Weird")
else:
print ("Weird")