Python basic algorithm collection (5)-number sorting

Last issue we wrote the algorithm for the issue of corporate bonuses. This time we will write a basic algorithm for sorting numbers.

We require: the user enters 5 random numbers, sorted by the sort() function, there is a parameter in the sort function, when it is true, it means descending order, when it is false, it means ascending order, and reverse=false is the default. The ascending order of the entered numbers is the default.

j=[]
for i in range(5):
    x=int(input('integer:\n'))
    j.append(x)
j.sort(reverse=True)#排序函数sort(reverse=false),参数reverse=True表示降序
#或false(升序。默认)
print (j)

 

Guess you like

Origin blog.csdn.net/weixin_43115314/article/details/113969363