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://www.codercto.com/courses/l/10.html

查看所有标签

The Little Prover

The Little Prover

Daniel P. Friedman、Carl Eastlund / The MIT Press / 2015-7-10 / USD 38.00

[FROM www.amazon.com]: The Little Prover introduces inductive proofs as a way to determine facts about computer programs. It is written in an approachable, engaging style of question-and-answer, wi......一起来看看 《The Little Prover》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

MD5 加密
MD5 加密

MD5 加密工具