網站首頁 數碼 家常菜譜 教育 旅行 汽車 女性 創意摺紙 手抄報 簡筆畫 影視 特產 生活 健康養生 電腦 熱點
當前位置:秒知館 > 生活 > 

python偶數怎麼表達

欄目: 生活 / 發佈於: / 人氣:2.83W

在python編譯器中,新建一個空白的PYTHON文檔;輸入:

n = float(input("Please input a number: "))

if n % 2 == 0:

print("This is an even")

elif n % 2 != 0:

print("This is an odd")

如果輸入的數字是偶數,輸出的文字爲“This is an even”。如果輸入的數字是奇數,輸出的文字爲“This is an odd”。

python偶數怎麼表達 python判斷偶數奇數

python怎麼判斷奇數偶數

1、首先開啟JUPYTER NOTEBOOK,新建一個空白的PYTHON文檔。也可以用其它編譯器的。

python偶數怎麼表達 python判斷偶數奇數 第2張

2、輸入以下內容:

num1 = int(input("Please input a number: "))

num2 = int(input("Please input a number: "))

if num1 % num2 == 0:

print("This is OK.")

elif num1 % num2 != 0:

print("This is NOT OK")

如果輸入的數字爲偶數,文檔就會返回文字"This is OK”;如果輸入的數字是奇數,文檔就會返回文字"This is NOT OK”。