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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
Python程序:統(tǒng)計(jì)集合中的正數(shù)和負(fù)數(shù)

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

寫(xiě)一個(gè) Python 程序來(lái)計(jì)算集合中的正數(shù)和負(fù)數(shù)。for 循環(huán)(用于 pongtSet 中的 eoVal)迭代所有集合項(xiàng)。if 條件(if(eoVal >= 0))檢查 Set 項(xiàng)是否大于或等于零。如果為真,我們?cè)谡嫌?jì)數(shù)上加一;否則,將負(fù)集計(jì)數(shù)值加 1。

# Count of Set Positive and Negative Numbers

pongtSet = {6, -33, 99, -28, -56, 11, -45, -43}
print("Positive and Negative Set Items = ", pongtSet)

sPositiveCount = sNegativeCount = 0

for eoVal in pongtSet:
    if(eoVal >= 0):
        sPositiveCount = sPositiveCount + 1
    else:
        sNegativeCount = sNegativeCount + 1

print("The Count of Positive Numbers in pongtSet = ", sPositiveCount)
print("The Count of Negative Numbers in pongtSet = ", sNegativeCount)

Python 程序計(jì)算集合中的正數(shù)和負(fù)數(shù)

該 Python 正數(shù)和負(fù)數(shù)示例允許使用 for 循環(huán)范圍輸入設(shè)置項(xiàng)。

# Count of Set Positive and Negative Numbers

pongtSet = set()

number = int(input("Enter the Total Positive Negative Set Items = "))
for i in range(1, number + 1):
    value = int(input("Enter the %d Set Item = " %i))
    pongtSet.add(value)

print("Positive and Negative Set Items = ", pongtSet)

sPositiveCount = sNegativeCount = 0

for eoVal in pongtSet:
    if(eoVal >= 0):
        sPositiveCount = sPositiveCount + 1
    else:
        sNegativeCount = sNegativeCount + 1

print("The Count of Positive Numbers in pongtSet = ", sPositiveCount)
print("The Count of Negative  Numbers in pongtSet = ", sNegativeCount)

Python 計(jì)數(shù)正負(fù)集合數(shù)輸出

Enter the Total Positive Negative Set Items = 4
Enter the 1 Set Item = -22
Enter the 2 Set Item = -99
Enter the 3 Set Item = 8
Enter the 4 Set Item = -67
Positive and Negative Set Items =  {8, -22, -99, -67}
The Count of Positive Numbers in pongtSet =  1
The Count of Negative  Numbers in pongtSet =  3

在這個(gè) Python 集的例子中,我們創(chuàng)建了一個(gè) countofsetpositiveandneblenumbers 函數(shù),該函數(shù)返回正數(shù)和負(fù)數(shù)的計(jì)數(shù)。

# Count of Set Positive and Negative Numbers

def CountOfSetPositiveandNegativeNumbers(pongtSet):
    sPositiveCount = sNegativeCount = 0

    for eoVal in pongtSet:
        if(eoVal >= 0):
            sPositiveCount = sPositiveCount + 1
        else:
            sNegativeCount = sNegativeCount + 1
    return sPositiveCount, sNegativeCount

pongtSet = set()

number = int(input("Enter the Total Positive Negative Set Items = "))
for i in range(1, number + 1):
    value = int(input("Enter the %d Set Item = " %i))
    pongtSet.add(value)

print("Positive and Negative Set Items = ", pongtSet)

sECount, sOCount = CountOfSetPositiveandNegativeNumbers(pongtSet)
print("The Count of Positive Numbers in pongtSet = ", sECount)
print("The Count of Negative  Numbers in pongtSet = ", sOCount)
Enter the Total Positive Negative Set Items = 6
Enter the 1 Set Item = 22
Enter the 2 Set Item = -90
Enter the 3 Set Item = -78
Enter the 4 Set Item = 9
Enter the 5 Set Item = 32
Enter the 6 Set Item = 8
Positive and Negative Set Items =  {32, -90, 8, 9, -78, 22}
The Count of Positive Numbers in pongtSet =  4
The Count of Negative  Numbers in pongtSet =  2

當(dāng)前文章:Python程序:統(tǒng)計(jì)集合中的正數(shù)和負(fù)數(shù)
文章轉(zhuǎn)載:http://m.5511xx.com/article/dphjhdo.html