Python Odd or Even Check
The following example determines whether a number is odd or even:
Example (Python 3.0+)
Filename : test.py
author by : www.runoob.com
Python Odd or Even Check
If it is even, the remainder on division by 2 is 0
If the remainder is 1, it is odd
num
=
int
(
input
(
"
Enter a number:
"
)
)
if
(
num
%
2
)
==
0
:
(
"
{0} is even
"
.
format
(
num
)
)
else
:
(
"
{0} is odd
"
.
format
(
num
)
)
We can also implement this with nested if statements:
The output of the code above is:
输入一个数字: 3
3 是奇数
Python3 Examples