Example 002 Python basis: three digital output Sorting

Enter three integers x, y, z, from small to large number of these three output please

Code:

 1 x = int(input('x: '))
 2 y = int(input('y: '))
 3 z = int(input('z: '))
 4 a = []
 5 a.append(x)
 6 a.append(y)
 7 a.append(z)
 8 if a[0] < a[1]:
 9     if a[1] < a[2]:
10         print(a[0], a[1], a[2])
11     elif a[0] < a[2]:
12         print(a[0], a[2], a[1])
13     else:
14         print(a[2], a[0], a[1])
15 elif a[1] > a[2]:
16     print(a[2], a[1], a[0])
17 elif a[0] > a[2]:
18     print(a[1], a[2], a[0])
19 else:
20     print(a[1], a[0], a[2])

 result:

X: 1 
Y:
. 3 Z: . 5 sorting results: 135



X: 1
Y:. 5
Z:. 3
sorting results: 135

 

X:. 3
Y: 1
Z:. 5
sorting results: 135

 

X:. 3
Y:. 5
Z: 1
Sort Results: 135

 

x: 5
y: 1
z: 3
排序结果: 1 3 5

 

x: 5
y: 3
z: 1
排序结果: 1 3 5

 

Guess you like

Origin www.cnblogs.com/ccdblogs/p/11372856.html