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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python 程序:按降序排序列表項目

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

在蘭考等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計,全網(wǎng)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),蘭考網(wǎng)站建設(shè)費用合理。

編寫一個 Python 程序,按照降序?qū)α斜眄椷M(jìn)行排序。在這個 Python 示例中,我們使用列表排序和反向方法對列表進(jìn)行降序排序。

intlist = []
intlistTot = int(input("Total Number of List Items to Sort = "))

for i in range(1, intlistTot + 1):
    intlistvalue = int(input("Please enter the %d List Item = "  %i))
    intlist.append(intlistvalue)

intlist.sort()
intlist.reverse()

print('List Items After Sorting in Descending Order')
print(intlist)

在這個 Python 程序中,我們使用了嵌套 for 循環(huán)和 temp 變量對列表項進(jìn)行降序排序。

intlist = []
intlistTot = int(input("Total Number of List Items to Sort = "))

for i in range(1, intlistTot + 1):
    intlistvalue = int(input("Please enter the %d List Item = "  %i))
    intlist.append(intlistvalue)

for i in range(len(intlist)):
    for j in range(i + 1, len(intlist)):
        if(intlist[i] < intlist[j]):
            temp = intlist[i]
            intlist[i] = intlist[j]
            intlist[j] = temp

print('List Items After Sorting in Descending Order')
for i in range(len(intlist)):
    print(intlist[i], end = '   ')
Total Number of List Items to Sort = 8
Please enter the 1 List Item = 17
Please enter the 2 List Item = 47
Please enter the 3 List Item = 12
Please enter the 4 List Item = 99
Please enter the 5 List Item = 55
Please enter the 6 List Item = 4
Please enter the 7 List Item = 60
Please enter the 8 List Item = 75
List Items After Sorting in Descending Order
99   75   60   55   47   17   12   4

Python 程序,使用 while 循環(huán)按降序?qū)α斜眄椷M(jìn)行排序。

intlist = []
intlistTot = int(input("Total Number of List Items to Sort = "))

i = 1
while(i <= intlistTot):
    intlistvalue = int(input("Please enter the %d List Item = "  %i))
    intlist.append(intlistvalue)
    i = i + 1

i = 0
while(i < len(intlist)):
    j = i + 1
    while j < len(intlist):
        if(intlist[i] < intlist[j]):
            temp = intlist[i]
            intlist[i] = intlist[j]
            intlist[j] = temp
        j = j + 1
    i = i + 1

print('List Items After Sorting in Descending Order')
i = 0
while(i < len(intlist)):
    print(intlist[i], end = '   ')
    i = i + 1
Total Number of List Items to Sort = 7
Please enter the 1 List Item = 19
Please enter the 2 List Item = 55
Please enter the 3 List Item = 89
Please enter the 4 List Item = 32
Please enter the 5 List Item = 47
Please enter the 6 List Item = 15
Please enter the 7 List Item = 7
List Items After Sorting in Descending Order
89   55   47   32   19   15   7

文章題目:Python 程序:按降序排序列表項目
轉(zhuǎn)載源于:http://m.5511xx.com/article/dhopcph.html