日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python 程序:打印元組中偶數(shù)

創(chuàng)新互聯(lián)python教程:

編寫一個(gè) Python 程序,使用 for 循環(huán)范圍打印元組中的偶數(shù)。if 語句(if(evTuple[i] % 2 == 0))檢查每個(gè) Tuple 項(xiàng)是否可以被 2 整除。如果為真,則打印該元組偶數(shù)。

# Tuple Even Numbers

evTuple = (3, 78, 67, 34, 88, 11, 23, 19)
print("Tuple Items = ", evTuple)

print("\nThe Even Numbers in this evTuple Tuple are:")
for i in range(len(evTuple)):
    if(evTuple[i] % 2 == 0):
        print(evTuple[i], end = "  ")
Tuple Items =  (3, 78, 67, 34, 88, 11, 23, 19)

The Even Numbers in this evTuple Tuple are:
78  34  88

使用 For 循環(huán)打印元組中偶數(shù)的 Python 程序。

在這個(gè) Python 偶數(shù)示例中,我們使用 for 循環(huán)(針對 evTuple 中的 tup)來迭代實(shí)際的 Tuple 項(xiàng)。

# Tuple Even Numbers

evTuple = (19, 25, 32, 44, 17, 66, 11, 98)
print("Tuple Items = ", evTuple)

print("\nThe Even Numbers in this evTuple Tuple are:")
for tup in evTuple:
    if(tup % 2 == 0):
        print(tup, end = "  ")
Tuple Items =  (19, 25, 32, 44, 17, 66, 11, 98)

The Even Numbers in this evTuple Tuple are:
32  44  66  98

Python 程序使用 While 循環(huán)返回或顯示元組中的偶數(shù)。

# Tuple Even Numbers

evTuple = (25, 12, 19, 44, 66, 79, 89, 22, 46) 
print("Tuple Items = ", evTuple)

i = 0

print("\nThe Even Numbers in this evTuple Tuple are:")
while (i < len(evTuple)):
    if(evTuple[i] % 2 == 0):
        print(evTuple[i], end = "  ")
    i = i + 1
Tuple Items =  (25, 12, 19, 44, 66, 79, 89, 22, 46)

The Even Numbers in this evTuple Tuple are:
12  44  66  22  46

在這個(gè) Python 元組的例子中,我們創(chuàng)建了一個(gè)函數(shù)(tuplevennumbers(evTuple))來查找和打印偶數(shù)。

# Tuple Even Numbers

def tupleEvenNumbers(evTuple):
    for tup in evTuple:
        if(tup % 2 == 0):
            print(tup, end = "  ")

evTuple = (19, 32, 25, 77, 44, 56, 89, 45, 98, 122, 55, 12) 
print("Tuple Items = ", evTuple)

print("\nThe Even Numbers in this evTuple Tuple are:")
tupleEvenNumbers(evTuple)


分享題目:Python 程序:打印元組中偶數(shù)
轉(zhuǎn)載源于:http://www.5511xx.com/article/dhgjdes.html