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

專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)元寶山免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千多家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
寫(xiě)一個(gè) Python 程序來(lái)查找大于平均值的列表項(xiàng)。這個(gè) python 示例允許我們輸入列表項(xiàng),然后我們會(huì)找到列表項(xiàng)的平均值。接下來(lái),for 循環(huán)將迭代列表項(xiàng),if 條件根據(jù)列表平均值檢查每個(gè)項(xiàng)。最后,如果大于平均值,則打印該列表項(xiàng)。
listAvg = []
Number = int(input("Total Number of List Items = "))
for i in range(1, Number + 1):
value = int(input("Enter the %d List Item = " %i))
listAvg.append(value)
total = sum(listAvg)
avg = total / Number
print('\nList Sum = {0} and Average = {1}'.format(total, avg))
print('Total List Items Greater than the List Average')
for i in range(len(listAvg)):
if listAvg[i] > avg:
print(listAvg[i], end = ' ')這個(gè) Python 示例使用 for 循環(huán)查找大于平均值的列表項(xiàng)。
listAvg = []
Number = int(input("Total Number of List Items = "))
total = 0
for i in range(Number):
value = int(input("Enter the %d List Item = " %(i+1)))
listAvg.append(value)
total = total + listAvg[i]
avg = total / Number
print('\nList Sum = {0} and Average = {1}'.format(total, avg))
print('Total List Items Greater than the List Average')
for i in range(len(listAvg)):
if listAvg[i] > avg:
print(listAvg[i], end = ' ')Total Number of List Items = 7
Enter the 1 List Item = 22
Enter the 2 List Item = 9
Enter the 3 List Item = 11
Enter the 4 List Item = 18
Enter the 5 List Item = 29
Enter the 6 List Item = 139
Enter the 7 List Item = 44
List Sum = 272 and Average = 38.857142857142854
Total List Items Greater than the List Average
139 44 Python 程序使用 while 循環(huán)查找大于平均值的列表項(xiàng)。
listAvg = []
Number = int(input("Total Number of List Items = "))
total = 0
i = 1
while(i <= Number):
value = int(input("Enter the %d List Item = " %(i+1)))
listAvg.append(value)
i = i + 1
i = 0
while(i < Number):
total = total + listAvg[i]
i = i + 1
avg = total / Number
print('\nList Sum = {0} and Average = {1}'.format(total, avg))
print('Total List Items Greater than the List Average')
for i in range(len(listAvg)):
if listAvg[i] > avg:
print(listAvg[i], end = ' ')Total Number of List Items = 9
Enter the 2 List Item = 4
Enter the 3 List Item = 11
Enter the 4 List Item = 3
Enter the 5 List Item = 2
Enter the 6 List Item = 9
Enter the 7 List Item = 22
Enter the 8 List Item = 7
Enter the 9 List Item = 15
Enter the 10 List Item = 17
List Sum = 90 and Average = 10.0
Total List Items Greater than the List Average
11 22 15 17 本文題目:Python程序:找到大于平均值的列表項(xiàng)
標(biāo)題路徑:http://fisionsoft.com.cn/article/dhdsede.html


咨詢
建站咨詢
