python偶数怎么表达

Python051

python偶数怎么表达,第1张

在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怎么判断奇数偶数

1、首先打开JUPYTER NOTEBOOK,新建一个空白的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”。

>>>l=[9,8,7,6,5,4,3,2,1]

>>>l[::2]=sorted(l[::2])

>>>l

[1, 8, 3, 6, 5, 4, 7, 2, 9]

>>>