判断奇偶的功能函数

1 def ji_ou(n):
2         if n & 1 == 1:
3                 print("n is ji shu")
4         else:
5                 print("n is ou shu")
6 
7 if __name__ == "__main__":
8         n = int(input("enter the num:"))
9         ji_ou(n)

数字n 和 1 相与,如果结果为1,则为奇数;否则为偶数。

正数和负数皆可

posted @ 2017-02-24 18:43  小黄人python  阅读(2961)  评论(0编辑  收藏  举报