Latest web development tutorials

Python determine odd and even

Document Object Reference Examples Python3

The following examples are used to determine whether a number is odd or even:

# -*- coding: UTF-8 -*-

# Filename : test.py
# author by : www.w3big.com

# Python 判断奇数偶数
# 如果是偶数除于 2 余数为 0
# 如果余数为 1 则为奇数

num = int(input("输入一个数字: "))
if (num % 2) == 0:
   print("{0} 是偶数".format(num))
else:
   print("{0} 是奇数".format(num))

We can also use the embedded if statement to achieve:

Execute the above code output results:

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

Document Object Reference Examples Python3