小明问了我一个问题:
如何用python来做奇偶数的判断呢?
任务:
给定整数n,请执行以下条件操作:
如果n是奇数,请打印Weird
如果n是偶数且在2-5的范围内,则打印Not Weird
如果n是偶数且在6-20的范围内,则打印Weird
如果n是偶数且大于等于20,则打印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.
Sample Input 0:
3
Sample Output 0:
Weird
Sample Input 1:
24
Sample Output 1:
Not Weird
我的代码如下:
n = int(input().strip())
# if n % 2 == 0:
if n & 1 == False:
if 2 < n < 5:
print('Not Weird')
elif 6 < n <= 20:
print('Weird')
elif n > 20:
print('Not Weird&#