&g...">
菜鸟笔记
提升您的技术认知

python实现输入三个整数x,y,z,请把这三个数由小到大输出-ag真人游戏

输入三个整数x,y,z,请把这三个数由小到大输出,如果用python来实现,可以有好多种方法。

方法一: 

>>> import re
>>> x, y, z = map(int, re.split(r"[ |,] ", raw_input("enter three number: ")))
enter three number: 4,3,2
>>> max = max(x, y, z)
>>> min = min(x, y, z)
>>> mid = [item for item in (x,y,z) if not item in (min, max)][0]
>>> print(min, mid, max)
(2, 3, 4)

方法二:

>>> import re
>>> lst = map(int, re.split(r"[ |,] ", raw_input("enter three number: ")))
enter three number: 3 1 5
>>> for item in sorted(lst):
...     print item,
1 3 5
>>>

方法三:

x = int(input("enter 1st number: "))
y = int(input("enter 2nd number: "))
z = int(input("enter 3rd number: "))
if x > y:
    x, y = y, x
if x > z:
    x, z = z, x
if y > z:
    y, z = z, y
print(x, y, z)

 

网站地图