日韩无码专区无码一级三级片|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程序:統(tǒng)計(jì)元組中偶數(shù)和奇數(shù)

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

萍鄉(xiāng)網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。成都創(chuàng)新互聯(lián)公司公司2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。

編寫一個(gè) Python 程序,使用 for 循環(huán)范圍來計(jì)算元組中的偶數(shù)和奇數(shù)(對于 i in 范圍(len(evodTuple))。if 條件(if(evodTuple[i] % 2 == 0))檢查 Tuple 項(xiàng)是否能被 2 整除。如果為真,我們給偶數(shù)元組計(jì)數(shù)加一;否則,給奇數(shù)元組計(jì)數(shù)值加一。

# Count of Tuple Even and Odd Numbers

evodTuple = (2, 33, 45, 88, 77, 98, 54, 0, 17)
print("Even and Odd Tuple Items = ", evodTuple)

tEvenCount = tOddCount = 0

for i in range(len(evodTuple)):
    if(evodTuple[i] % 2 == 0):
        tEvenCount = tEvenCount + 1
    else:
        tOddCount = tOddCount + 1

print("The Count of Even Numbers in evodTuple = ", tEvenCount)
print("The Count of Odd  Numbers in evodTuple = ", tOddCount)

計(jì)算元組中偶數(shù)和奇數(shù)的 Python 程序

在這個(gè) Python 示例中,我們使用 for 循環(huán)(用于 evodTuple 中的 oetup)來迭代實(shí)際的元組值,并檢查它們是否能被等于零的 2 整除。

# Count of Tuple Even and Odd Numbers

evodTuple = (11, 34, 17, 44, 66, 19, 89, 64, 90)
print("Even and Odd Tuple Items = ", evodTuple)

tEvenCount = tOddCount = 0
for oetup in evodTuple:
    if(oetup % 2 == 0):
        tEvenCount = tEvenCount + 1
    else:
        tOddCount = tOddCount + 1

print("The Count of Even Numbers in evodTuple = ", tEvenCount)
print("The Count of Odd  Numbers in evodTuple = ", tOddCount)
Even and Odd Tuple Items =  (11, 34, 17, 44, 66, 19, 89, 64, 90)
The Count of Even Numbers in evodTuple =  5
The Count of Odd  Numbers in evodTuple =  4

使用 While 循環(huán)計(jì)算元組偶數(shù)和奇數(shù)的 Python 程序。

# Count of Tuple Even and Odd Numbers

evodTuple = (64, 45, 12, 15, 68, 55, 37, 25, 120, 205)
print("Even and Odd Tuple Items = ", evodTuple)

tEvenCount = tOddCount = 0
i = 0

while (i < len(evodTuple)):
    if(evodTuple[i] % 2 == 0):
        tEvenCount = tEvenCount + 1
    else:
        tOddCount = tOddCount + 1
    i = i + 1

print("The Count of Even Numbers in evodTuple = ", tEvenCount)
print("The Count of Odd  Numbers in evodTuple = ", tOddCount)
Even and Odd Tuple Items =  (64, 45, 12, 15, 68, 55, 37, 25, 120, 205)
The Count of Even Numbers in evodTuple =  4
The Count of Odd  Numbers in evodTuple =  6

在這個(gè) Python 元組的例子中,我們創(chuàng)建了一個(gè) CountOfEvenOddOddNumbers 函數(shù),返回偶數(shù)和奇數(shù)的計(jì)數(shù)。

# Count of Tuple Even and Odd Numbers

def CountOfEvenOddOddNumbers(evodTuple):
    tEvenCount = tOddCount = 0
    for oetup in evodTuple:
        if(oetup % 2 == 0):
            tEvenCount = tEvenCount + 1
        else:
            tOddCount = tOddCount + 1
    return tEvenCount, tOddCount

evodTuple = (12, 26, 77, 99, 66, 75, 14, 256, 19, 81, 11, 33) 
print("Even and Odd Tuple Items = ", evodTuple)

evenCount, oddCount = CountOfEvenOddOddNumbers(evodTuple)
print("The Count of Even Numbers in evodTuple = ", evenCount)
print("The Count of Odd  Numbers in evodTuple = ", oddCount)
Even and Odd Tuple Items =  (12, 26, 77, 99, 66, 75, 14, 256, 19, 81, 11, 33)
The Count of Even Numbers in evodTuple =  5
The Count of Odd  Numbers in evodTuple =  7

網(wǎng)頁題目:Python程序:統(tǒng)計(jì)元組中偶數(shù)和奇數(shù)
網(wǎng)站地址:http://www.5511xx.com/article/dpsdoej.html