网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容 知识问答

如何用PYTHON判断奇偶数

时间:2024-10-13 10:40:45

1、首先我们打开JUPYTER NOTEBOOK,新建一个空白的PYTHON文档。当然也可以用其它编译器的。

如何用PYTHON判断奇偶数

3、n = int(input("Please input a number: "))if n % 2 == 0: print("This is an even.")elif n % 2 != 0: print("This is an odd")我们要注意要定义输入的变量是整型,因为字符串是不能进行运算的。

如何用PYTHON判断奇偶数

5、n = int(input(&孥恶膈茯quot;Please input a number: "))if n % 4 == 0: print("This number is a multiple of 4.")elif n % 4 != 0: print("This number is not a multiple of 4")除了除以2以外,还可以除以4来作为判断,主要看自己想要判断什么数字。

如何用PYTHON判断奇偶数
© 2025 智德知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com