python如何提取奇数_Python 获取奇数和偶数

获取奇数

#!/usr/bin/python3

# -*- coding:utf-8 -*-

for i in range(1,11):

if (i % 2) == 0:

continue

else:

print(“{0} is odd”.format(i))

执行结果:

1 is odd

3 is odd

5 is odd

7 is odd

9 is odd

获取偶数

#!/usr/bin/python3

# -*- coding:utf-8 -*-

for i in range(1,11):

if (i % 2) == 0:

print(“{0} is even”.format(i))

执行结果:

2 is even

4 is even

6 is even

8 is even

10 is even

判断奇偶数

#

# 如果是偶数除于 2 余数为 0

# 如果余数为 1 则为奇数

#!/usr/bin/python3

# -*- coding:utf-8 -*-

num = int(input(“Please input number: “))

if (num % 2) == 0:

print(“{0} is even”.format(num))

else:

print(“{0} is odd”.format(num))

九九乘法表

#!/u

你可能感兴趣的:(python如何提取奇数)