Python版: 1 #!/usr/bin/python 2 # -*- coding: UTF-8 -*- 3 import math 4 5 """ 6 三个整数x,y,z,请把这三个数由小到大输出。 7 """ 8 a = [3,6,4,3] 9 print len(a) 10 for i in range(0,len(a)): 11 for j in range(i,len(a)): 12
Python版:
1 #!/usr/bin/python2 # -*- coding: UTF-8 -*-
3 import math
4
5 """
6 三个整数x,y,z,请把这三个数由小到大输出。
7 """
8 a = [3,6,4,3]
9 print len(a)
10 for i in range(0,len(a)):
11 for j in range(i,len(a)):
12 if a[j] < a[j - 1]:#冒泡排序,判断相邻两个数大小
13 tem = a[j]
14 a[j] = a[j - 1]
15 a[j - 1] = tem
16 for k in range(0,len(a)):
17 print a[k]
结果:
33
4
6