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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:計(jì)算元組項(xiàng)和

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

編寫一個 Python 程序來查找元組中所有項(xiàng)目的總和。這里,我們使用 Tuple sum 函數(shù)返回所有 Tuple 項(xiàng)的總和。

# Tuple Sum of All Items

numTuple = (20, 40, 65, 75, 80, 220)
print("Tuple Items = ", numTuple)

tupleSum = sum(numTuple)
print("\nThe Sum of numTuple Tuple Items = ", tupleSum)
Tuple Items =  (20, 40, 65, 75, 80, 220)

The Sum of numTuple Tuple Items =  500

尋找元組項(xiàng)之和的 Python 程序

在這個 Python 示例中,for 循環(huán)(用于 numTuple 中的 tup)迭代所有元組項(xiàng)。在循環(huán)(tupleSum = tupleSum + tup)中,我們將每個元組項(xiàng)添加到 tupleSum 中,并打印相同的內(nèi)容。

# Tuple Sum of All Items

numTuple = (11, 22, 33, 44, 55, 66, 77, 88, 99)
print("Odd Tuple Items = ", numTuple)

tupleSum = 0
for tup in numTuple:
    tupleSum = tupleSum + tup

print("\nThe Sum of numTuple Tuple Items = ", tupleSum)
Odd Tuple Items =  (11, 22, 33, 44, 55, 66, 77, 88, 99)

The Sum of numTuple Tuple Items =  495

Python 程序使用 While 循環(huán)計(jì)算所有元組項(xiàng)的總和。

# Tuple Sum of All Items

numTuple = (25, 45, 65, 75, 95, 125, 256, 725)
print("Odd Tuple Items = ", numTuple)

tupleSum = 0
i = 0

while (i < len(numTuple)):
    tupleSum = tupleSum + numTuple[i]
    i = i + 1

print("\nThe Sum of numTuple Tuple Items = ", tupleSum)
Odd Tuple Items =  (25, 45, 65, 75, 95, 125, 256, 725)

The Sum of numTuple Tuple Items =  1411

在這個 Python Tuple 示例中,我們創(chuàng)建了一個 sumOfTupleItems(numTuple)函數(shù),該函數(shù)將計(jì)算并返回所有 tuple 項(xiàng)的總和。

# Tuple Sum

def sumOfTupleItems(numTuple):
    tupleSum = 0
    for tup in numTuple:
        tupleSum = tupleSum + tup
    return tupleSum

numTuple = (16, 31, 24, 98, 123, 78, 56, 67, 22)
print("Tuple Items = ", numTuple)

tSum = sumOfTupleItems(numTuple)
print("\nThe Sum of numTuple Tuple Items = ", tSum)


分享題目:Python程序:計(jì)算元組項(xiàng)和
網(wǎng)站URL:http://www.5511xx.com/article/dhpiged.html