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

鎮(zhèn)安網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、響應(yīng)式網(wǎng)站開(kāi)發(fā)等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(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)行。專(zhuān)注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
編寫(xiě)一個(gè) Python 程序來(lái)打印集合中的正數(shù)或項(xiàng)目。for 循環(huán)(PositiveSet 中的 posival)內(nèi)的 if 語(yǔ)句(if(posival > = 0))檢查 Set 項(xiàng)是否大于或等于零。如果為真,則打印該正數(shù)。
# Set Positive Numbers
PositiveSet = {7, -8, -11, 4, -85, 14, -22, 78, 11}
print("Positive Set Items = ", PositiveSet)
print("\nThe Positive Numbers in this PositiveSet Set are:")
for posVal in PositiveSet:
if(posVal >= 0):
print(posVal, end = " ")在 Python 集中打印正數(shù)輸出
Positive Set Items = {4, 7, -22, 11, -85, 14, 78, -11, -8}
The Positive Numbers in this PositiveSet Set are:
4 7 11 14 78 在這個(gè) Python 程序中,我們?cè)试S您輸入集合項(xiàng)目并在集合中打印正數(shù)。
# Set Positive Numbers
positiveSet = set()
number = int(input("Enter the Total Positive Set Items = "))
for i in range(1, number + 1):
value = int(input("Enter the %d Set Item = " %i))
positiveSet.add(value)
print("Positive Set Items = ", positiveSet)
print("\nThe Positive Numbers in this positiveSet Set are:")
for posVal in positiveSet:
if(posVal >= 0):
print(posVal, end = " ")Python 打印正片集項(xiàng)目輸出
Enter the Total Positive Set Items = 4
Enter the 1 Set Item = -32
Enter the 2 Set Item = 23
Enter the 3 Set Item = -99
Enter the 4 Set Item = 77
Positive Set Items = {-32, 77, -99, 23}
The Positive Numbers in this positiveSet Set are:
77 23 在這個(gè) Python Set 的例子中,我們創(chuàng)建了一個(gè) setPositiveNumbers 函數(shù)來(lái)查找和打印正數(shù)。
# Set Positive Numbers
def setPositiveNumbers(positiveSet):
for posVal in positiveSet:
if(posVal >= 0):
print(posVal, end = " ")
positiveSet = set()
number = int(input("Enter the Total Positive Set Items = "))
for i in range(1, number + 1):
value = int(input("Enter the %d Set Item = " %i))
positiveSet.add(value)
print("Positive Set Items = ", positiveSet)
print("\nThe Positive Numbers in this positiveSet Set are:")
setPositiveNumbers(positiveSet) 當(dāng)前標(biāo)題:Python程序:打印集合中正數(shù)
本文地址:http://www.5511xx.com/article/cocojdo.html


咨詢(xún)
建站咨詢(xún)
