Latest web development tutorials

Python determinare pari e dispari

Document Object Reference Esempi python3

Gli esempi che seguono sono utilizzati per determinare se un numero è pari o dispari:

# -*- 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))

Possiamo anche utilizzare l'incorporato if per ottenere:

Eseguire i risultati di output di codice di cui sopra:

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

Document Object Reference Esempi python3