比较三个数大小
1、题目要求
输入三个整数x,y,z,请把这三个数由小到大输出
2、程序分析
- 两个数比较大小很容易做到
- 三个数比较大小,只是多了一个次比较而已
3、示例代码
#coding=utf-8
def compare(x,y,z):
if x < y :
if x < z:
if z < y :
print x,z,y
else:
print x,y,z
else:
print z,x,y
else:
if y > z:
print z,y,x
else:
if x > z:
print y,z,x
else:
print y,x,z
compare(1,2,3)
compare(2,1,3)
compare(2,3,1)
compare(1,3,2)
compare(3,1,2)
compare(3,2,1)