**Language- Python 3 **
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 2 to 10, print Not Weird
- If n is even and in the inclusive range of 11 to 20, print Weird
- If n is even and greater than 20, print Not Weird
Input Format
A single line containing a positive integer, n.
Output Format
Print Weird if the number is weird. Otherwise, print Not Weird.
My Code:-
n=int(input())
if n%2==1:
print("Weird")
elif n%2==0:
if n>1:
if n<11:
print("Not Weird")
elif n%2==0:
if n>10:
if n<21:
print("Weird")
elif n>20:
print("Not Weird")
>Solution :
Your first elif will prevent the second one from ever being reached, and the position of the final elif is confusing.
Instead you can merge the other tests, and also combine the if tests into single pairs to make it easier to follow:
n=int(input())
if n%2==1:
print("Weird")
else:
if 1 < n < 11:
print("Not Weird")
if 10 < n < 21:
print("Weird")
if n > 20:
print("Not Weird")
You can then reduce it further still:
if 10 < n < 21:
print("Weird")
else:
print("Not Weird")