Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Odd or Even Check

Python Odd or Even Check

Document Object Reference Manual Python3 Examples

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

:

print

(

"

{0} is even

"

.

format

(

num

)

)

else

:

print

(

"

{0} is odd

"

.

format

(

num

)

)

We can also implement this with nested if statements:

The output of the code above is:


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

Document Object Reference Manual Python3 Examples