Suppose we have a number n. We shall have to check whether n is weird or not. Here a number is weird when − 1. The number is odd 2. The number is not in range 2 to 5 3. The number is even and in range 6 to 20
So, if the input is like n = 18, then the output will be Weird because it is even and in range 6 to 20.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(n): if n & 1: return "Weird" elif (n > 1 and n < 6) or n > 20: return "Not Weird" elif n > 6 and n < 21: return "Weird" n = 18 print(solve(n))