The problem is like this
My solution:
JavaScript
x
11
11
1
n= int(input())
2
if n%2==0:
3
if (n >=2 & n<=5):
4
print("Not Weird")
5
elif n >=6 & n<=20:
6
print("Weird")
7
else:
8
print ("Not Weired")
9
else:
10
print ("Weird")
11
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
:
JavaScript
1
11
11
1
n= int(input())
2
if n%2==0:
3
if (n >=2 and n<=5): #modified here!
4
print("Not Weird")
5
elif n >=6 and n<=20: #modified here!
6
print("Weird")
7
else:
8
print ("Not Weird")
9
else:
10
print ("Weird")
11