新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:打印集合中正數(shù)
創(chuàng)新互聯(lián)Python教程:

鎮(zhèn)安網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、APP開發(fā)、響應式網(wǎng)站開發(fā)等網(wǎng)站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)公司從2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設就選成都創(chuàng)新互聯(lián)公司。
編寫一個 Python 程序來打印集合中的正數(shù)或項目。for 循環(huán)(PositiveSet 中的 posival)內的 if 語句(if(posival > = 0))檢查 Set 項是否大于或等于零。如果為真,則打印該正數(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 在這個 Python 程序中,我們允許您輸入集合項目并在集合中打印正數(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 打印正片集項目輸出
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 在這個 Python Set 的例子中,我們創(chuàng)建了一個 setPositiveNumbers 函數(shù)來查找和打印正數(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) 本文標題:Python程序:打印集合中正數(shù)
文章出自:http://fisionsoft.com.cn/article/cocojdo.html


咨詢
建站咨詢
