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

查看所有标签

Introduction to Computer Science Using Python

Introduction to Computer Science Using Python

Dierbach, Charles / 2012-12 / $ 133.62

Introduction to Computer Science Using Python: A Computational Problem-Solving Focus introduces students to programming and computational problem-solving via a back-to-basics, step-by-step, objects-la......一起来看看 《Introduction to Computer Science Using Python》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

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

各进制数互转换器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具