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

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

新聞中心

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

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

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

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

# Tuple Negative Numbers

negTuple = (3, -8, -22, 4, -98, 14, -33, -78, 11)
print("Negative Tuple Items = ", negTuple)

print("\nThe Negative Numbers in negTuple Tuple are:")
for i in range(len(negTuple)):
    if(negTuple[i] < 0):
        print(negTuple[i], end = "  ")
Negative Tuple Items =  (3, -8, -22, 4, -98, 14, -33, -78, 11)

The Negative Numbers in negTuple Tuple are:
-8  -22  -98  -33  -78 

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

在這個(gè) Python 負(fù)數(shù)示例中,我們使用 for 循環(huán)(對(duì)于 negTuple 中的 ngtup)來(lái)迭代實(shí)際的元組項(xiàng)。

# Tuple Negative Numbers

negTuple = (25, -14, -28, 17, -61, -21, 89, 17, -48, 0)
print("Negative Tuple Items = ", negTuple)

print("\nThe Negative Numbers in this negTuple Tuple are:")
for ngtup in negTuple:
    if(ngtup < 0):
        print(ngtup, end = "  ")
Negative Tuple Items =  (25, -14, -28, 17, -61, -21, 89, 17, -48, 0)

The Negative Numbers in this negTuple Tuple are:
-14  -28  -61  -21  -48 

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

# Tuple Negative Numbers

negTuple = (11, -22, -45, 67, -98, -87, 0, 16, -120) 
print("Negative Tuple Items = ", negTuple)

i = 0

print("\nThe Negative Numbers in negTuple Tuple are:")
while (i < len(negTuple)):
    if(negTuple[i] < 0):
        print(negTuple[i], end = "  ")
    i = i + 1
Negative Tuple Items =  (11, -22, -45, 67, -98, -87, 0, 16, -120)

The Negative Numbers in negTuple Tuple are:
-22  -45  -98  -87  -120 

在這個(gè) Python Tuple 示例中,我們創(chuàng)建了一個(gè)函數(shù)(tupleNegativeNumbers(negTuple))來(lái)查找并打印負(fù)數(shù)。

# Tuple Negative Numbers

def tupleNegativeNumbers(negTuple):
    for potup in negTuple:
        if(potup < 0):
            print(potup, end = "  ")

negTuple = (9, -23, -17, 98, 66, -12, -77, 0, -2, 15) 
print("Negative Tuple Items = ", negTuple)

print("\nThe Negative Numbers in negTuple Tuple are:")
tupleNegativeNumbers(negTuple)


網(wǎng)站題目:Python程序:打印元組中負(fù)數(shù)
轉(zhuǎn)載來(lái)于:http://www.dlmjj.cn/article/dpigpee.html