您的位置:首页技术文章
文章详情页

python偶数怎么表达 python判断偶数奇数

浏览:62日期:2022-08-08 11:53:29

在python编译器中,新建一个空白的PYTHON文档;输入:

n = float(input('Please input a number: '))

if n % 2 == 0:

print('This is an even')

elif n % 2 != 0:

print('This is an odd')

如果输入的数字是偶数,输出的文字为“This is an even”。如果输入的数字是奇数,输出的文字为“This is an odd”。

python偶数怎么表达 python判断偶数奇数

python怎么判断奇数偶数

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

python偶数怎么表达 python判断偶数奇数

2、输入以下内容:

num1 = int(input('Please input a number: '))

num2 = int(input('Please input a number: '))

if num1 % num2 == 0:

print('This is OK.')

elif num1 % num2 != 0:

print('This is NOT OK')

如果输入的数字为偶数,文档就会返回文字'This is OK”;如果输入的数字是奇数,文档就会返回文字'This is NOT OK”。

标签: Python 编程
相关文章: