Python案例 005 (三位数字排序)

来源:互联网 发布:骨肉之躯 知乎 编辑:程序博客网 时间:2024/06/04 18:13



# -*- coding:utf-8 -*-"""enter 3  unit  ,and sort them"""L = []for x  in range(3):    L.append(int(raw_input("enter one unit data:\n")))L.sort()L.sort(reverse=True)print L# try with  bubble sortbubbleList = [12,123,45,78,43,21,99,78,45,34,22,26]bubbleLen = len(bubbleList)for i  in range(1 ,bubbleLen):    for j in range(1,bubbleLen - i+1):        if bubbleList[j-1] > bubbleList[j] :            bubbleList[j - 1] , bubbleList[j] =bubbleList[j] , bubbleList[j-1]        print bubbleListprint bubbleList