python输入三个整数x,y,z,请把这三个数由小到大输出
时间: 2023-05-30 21:03:22 浏览: 66
```python
x, y, z = map(int, input().split())
lst = [x, y, z]
lst.sort()
print(lst)
```
或者
```python
x, y, z = map(int, input().split())
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)
```
相关问题
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,请把这三个数由小到大输出
好的,以下是 Python 的代码实现:
```
x = int(input("请输入第一个整数x:"))
y = int(input("请输入第二个整数y:"))
z = int(input("请输入第三个整数z:"))
lst = [x, y, z]
lst.sort()
print("三个整数由小到大排序的结果为:", lst)
```
你可以将这段代码复制到 Python 环境中运行,输入三个整数后即可看到排序结果。
相关推荐
![](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)