用python求输入三个整数x,y,z,请把这三个数由小到大输出。
时间: 2024-06-13 09:03:48 浏览: 21
可以使用Python内置的sort()函数对三个数进行排序,然后输出即可。
代码如下:
```
x, y, z = map(int, input().split())
lst = [x, y, z]
lst.sort()
print(lst)
```
输出结果为:
```
[1, 2, 3]
```
相关问题
python输入三个整数x, y, z,请把这三个数由小到大输出。
以下是两种Python将三个整数由小到大输出的方法:
1. 方法一:
```python
x = int(input('x:'))
y = int(input('y:'))
z = int(input('z:'))
min = x
mid = y
max = z
if (x > y):
temp = y
y = x
x = temp
if (x > z):
temp = z
z = x
x = temp
if (y > z):
temp = y
y = z
z = temp
print('order:' + str(x) + ' ' + str(y) + ' ' + str(z))
```
2. 第二种方法:
```python
x = int(input('第一个整数x: '))
y = int(input('第二个整数y: '))
z = int(input('第三个整数z: '))
max = x
if y > x:
max = y
y = x
x = max
if z > y:
max = z
z = y
y = max
if y > x:
max = y
y = x
x = max
print(x, y, z)
```
用python 输入三个整数x,y,z,请把这三个数由小到大输出
```
x = int(input("请输入第一个整数:"))
y = int(input("请输入第二个整数:"))
z = int(input("请输入第三个整数:"))
if x < y:
if y < z:
print(x, y, z)
else:
if x < z:
print(x, z, y)
else:
print(z, x, y)
else:
if x < z:
print(y, x, z)
else:
if y < z:
print(y, z, x)
else:
print(z, y, x)
```
另一种简单的方法是使用列表的sort()方法:
```
x = int(input("请输入第一个整数:"))
y = int(input("请输入第二个整数:"))
z = int(input("请输入第三个整数:"))
lst = [x, y, z]
lst.sort()
print(lst)
```
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)