本文目錄一覽:
python從鍵盤輸入一個整數,打印出它是奇數還是偶數要怎麼寫?
num = int(input(“輸入一個數字: “))if (num % 2) == 0: print(“{0} 是偶數”.format(num))else: print(“{0} 是奇數”.format(num))
python在100到200之間的一個隨機的偶數?
建一個數組
100,102,104,…,200
隨機生成 1-50 的數,作為 下標,指向 對應的偶數 就行
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import random
x = range(100,201,2)
i = 0
while i=50:
index = random.randint(1,50)
print(“%d – %d” % (index,x[index]))
i += 1
#(“Hello, World!”)
結果: 部分
1 – 102
1 – 102
15 – 130
13 – 126
49 – 198
4 – 108
30 – 160
45 – 190
一道簡單的python編程題?
按照題目要求編寫的哥德巴赫猜想的Python程序如下
def IsPrime(v):
if v=2:
for i in range(2,v//2+1):
if v%i==0:
return False
else:
return True
else:
return False
n=int(input(“輸入一個正偶數:”))
if n2 and n%2==0:
for i in range(1,n//2+1):
if IsPrime(i)==True and IsPrime(n-i)==True:
print(“%d=%d+%d” %(n,i,n-i))
else:
print(“輸入數據出錯!”)
源代碼(注意源代碼的縮進)
python偶數怎麼表達
在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怎麼判斷奇數偶數
1、首先打開JUPYTER NOTEBOOK,新建一個空白的PYTHON文檔。也可以用其它編譯器的。
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」。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/228764.html