Python 判断奇数偶数

Python 3 教程 · 2019-02-12 10:42:28

以下实例用于判断一个数字是否为奇数或偶数:

实例(Python 3.0+)

# Filename : test.py # author by : www.codercto.com # Python 判断奇数偶数 # 如果是偶数除于 2 余数为 0 # 如果余数为 1 则为奇数 num = int(input("输入一个数字: ")) if (num % 2) == 0: print("{0} 是偶数".format(num)) else: print("{0} 是奇数".format(num))

我们也可以使用内嵌 if 语句来实现:

执行以上代码输出结果为:

输入一个数字: 3
3 是奇数

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Thinking Recursively

Thinking Recursively

Eric S. Roberts / Wiley / 1986-1-17 / USD 85.67

The process of solving large problems by breaking them down into smaller, more simple problems that have identical forms. Thinking Recursively: A small text to solve large problems. Concentrating on t......一起来看看 《Thinking Recursively》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换