python123输入三个整数,在同一行内由小到大排序
时间: 2024-05-10 08:16:29 浏览: 16
可以使用Python内置的sorted()函数,将三个整数放入列表中,然后对列表进行排序,最后输出即可。以下是示例代码:
```
nums = input("请输入三个整数,用空格隔开:").split()
nums = [int(num) for num in nums]
nums = sorted(nums)
print(nums)
```
输入示例:
```
请输入三个整数,用空格隔开:3 1 5
```
输出示例:
```
[1, 3, 5]
```
相关问题
python输入三个整数按从大到小排序
可以使用以下代码实现:
a, b, c = input("请输入三个整数,用空格分隔:").split()
a, b, c = int(a), int(b), int(c)
if a > b:
a, b = b, a
if b > c:
b, c = c, b
if a > b:
a, b = b, a
print(c, b, a)
Python输入三个整数按从大到小排序
可以使用以下代码实现:
a, b, c = map(int, input().split())
if a > b:
a, b = b, a
if b > c:
b, c = c, b
if a > b:
a, b = b, a
print(c, b, a)
相关推荐
![](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)