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

創(chuàng)新互聯(lián)公司秉承實(shí)現(xiàn)全網(wǎng)價(jià)值營(yíng)銷的理念,以專業(yè)定制企業(yè)官網(wǎng),成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司,微信小程序開(kāi)發(fā),網(wǎng)頁(yè)設(shè)計(jì)制作,成都手機(jī)網(wǎng)站制作,營(yíng)銷型網(wǎng)站幫助傳統(tǒng)企業(yè)實(shí)現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級(jí)專業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對(duì)客戶都以感恩的心態(tài)奉獻(xiàn)自己的專業(yè)和所長(zhǎng)。
寫一個(gè) Python 程序來(lái)打印集合中的負(fù)數(shù)。for 循環(huán)中的 if 語(yǔ)句(if(negaVal < 0))檢查集合項(xiàng)是否小于零。如果為真,則打印負(fù)集數(shù)。
# Set Negative Numbers
NegativeSet = {6, -22, -33, 78, -88, 15, -55, -66, 17}
print("Negative Set Items = ", NegativeSet)
print("\nThe Negative Numbers in this NegativeSet Set are:")
for negaVal in NegativeSet:
if(negaVal < 0):
print(negaVal, end = " ")在 Python 集中打印負(fù)數(shù)輸出
Negative Set Items = {6, -88, -55, -22, 78, 15, 17, -66, -33}
The Negative Numbers in this NegativeSet Set are:
-88 -55 -22 -66 -33 這個(gè) Python 程序允許您輸入集合項(xiàng)目并在集合中打印負(fù)數(shù)。
# Set Negative Numbers
negativeSet = set()
number = int(input("Enter the Total Negative Set Items = "))
for i in range(1, number + 1):
value = int(input("Enter the %d Set Item = " %i))
negativeSet.add(value)
print("Negative Set Items = ", negativeSet)
print("\nThe Negative Numbers in this negativeSet Set are:")
for negaVal in negativeSet:
if(negaVal < 0):
print(negaVal, end = " ")在這個(gè) Python Set 示例中,我們創(chuàng)建了一個(gè) setnegativeNumbers 函數(shù),它可以查找并打印負(fù)數(shù)。
# Tuple Negative Numbers
def setnegativeNumbers(negativeSet):
for negVal in negativeSet:
if(negVal < 0):
print(negVal, end = " ")
negativeSet = set()
number = int(input("Enter the Total Negative Set Items = "))
for i in range(1, number + 1):
value = int(input("Enter the %d Set Item = " %i))
negativeSet.add(value)
print("Negative Set Items = ", negativeSet)
print("\nThe Negative Numbers in this negativeSet Set are:")
setnegativeNumbers(negativeSet)Enter the Total Negative Set Items = 5
Enter the 1 Set Item = 22
Enter the 2 Set Item = -33
Enter the 3 Set Item = -87
Enter the 4 Set Item = 58
Enter the 5 Set Item = -71
Negative Set Items = {-87, 22, -71, 58, -33}
The Negative Numbers in this negativeSet Set are:
-87 -71 -33 新聞標(biāo)題:Python程序:打印集合中負(fù)數(shù)
網(wǎng)站網(wǎng)址:http://m.fisionsoft.com.cn/article/dhssggs.html


咨詢
建站咨詢
