av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Python程序:統(tǒng)計(jì)元組中偶數(shù)和奇數(shù)

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

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

編寫一個(gè) Python 程序,使用 for 循環(huán)范圍來(lái)計(jì)算元組中的偶數(shù)和奇數(shù)(對(duì)于 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)來(lái)迭代實(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

當(dāng)前名稱:Python程序:統(tǒng)計(jì)元組中偶數(shù)和奇數(shù)
轉(zhuǎn)載來(lái)源:http://uogjgqi.cn/article/dpsdoej.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流