Python Determine Odd/Even

Document 对象参考手册Python3 Examples

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

Examples (Python 3.0+)

# Filename : test.py # author by : www.example.com # Python determines odd/even # If it is even, the remainder when divided 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 use nested if statements to implement this:

The output of the above code is:

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

Document 对象参考手册Python3 Examples

Other Extensions