日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

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

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

為溆浦等地區(qū)用戶(hù)提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及溆浦網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)、溆浦網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專(zhuān)業(yè)、用心的態(tài)度為用戶(hù)提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶(hù)的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!

編寫(xiě)一個(gè) Python 程序,使用 for 循環(huán)范圍打印元組中的正數(shù)。if 語(yǔ)句(if(posTuple[i] >= 0))檢查元組項(xiàng)是否大于或等于零。如果為真,則打印正元組編號(hào)。

# Tuple Positive Numbers

posTuple = (3, -8, 6, 4, -88, -11, 13, 19)
print("Positive Tuple Items = ", posTuple)

print("\nThe Positive Numbers in posTuple Tuple are:")
for i in range(len(posTuple)):
    if(posTuple[i] >= 0):
        print(posTuple[i], end = "  ")
Positive Tuple Items =  (3, -8, 6, 4, -88, -11, 13, 19)

The Positive Numbers in posTuple Tuple are:
3  6  4  13  19 

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

在這個(gè) Python 正數(shù)示例中,我們使用 for 循環(huán)(用于后置元組中的 potup)來(lái)迭代實(shí)際的元組后置項(xiàng)。

# Tuple Positive Numbers

posTuple = (25, 32, -14, 17, -6, -1, 98, 11, -9, 0)
print("Positive Tuple Items = ", posTuple)

print("\nThe Positive Numbers in this posTuple Tuple are:")
for potup in posTuple:
    if(potup >= 0):
        print(potup, end = "  ")
Positive Tuple Items =  (25, 32, -14, 17, -6, -1, 98, 11, -9, 0)

The Positive Numbers in this posTuple Tuple are:
25  32  17  98  11  0 

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

# Tuple Positive Numbers

posTuple = (25, -11, -22, 17, 0, -9, 43, 17, -10) 
print("Positive Tuple Items = ", posTuple)

i = 0

print("\nThe Positive Numbers in posTuple Tuple are:")
while (i < len(posTuple)):
    if(posTuple[i] >= 0):
        print(posTuple[i], end = "  ")
    i = i + 1
Positive Tuple Items =  (25, -11, -22, 17, 0, -9, 43, 17, -10)

The Positive Numbers in posTuple Tuple are:
25  17  0  43  17 

在這個(gè) Python Tuple 示例中,我們創(chuàng)建了一個(gè)函數(shù)(tuplepossivennumbers(posTuple))來(lái)查找和打印正數(shù)。

# Tuple Positive Numbers

def tuplePositiveNumbers(posTuple):
    for potup in posTuple:
        if(potup >= 0):
            print(potup, end = "  ")

posTuple = (19, -32, -17, 98, 44, -12, 0, 78, -2, 4, -5) 
print("Positive Tuple Items = ", posTuple)

print("\nThe Positive Numbers in this posTuple Tuple are:")
tuplePositiveNumbers(posTuple)


分享名稱(chēng):Python程序:打印元組中正數(shù)
分享鏈接:http://www.dlmjj.cn/article/dhceejj.html