python从从大到小排序三个整数
时间: 2024-01-23 17:36:12 浏览: 38
可以使用Python内置函数sorted()对三个整数进行排序,然后将排序后的结果以列表的形式返回。由于默认情况下sorted()是从小到大排序,因此需要在sorted()函数中添加reverse=True参数,使其按照从大到小的顺序排序。示例代码如下:
```python
def sort_three_nums_desc(a, b, c):
nums = [a, b, c]
sorted_nums = sorted(nums, reverse=True)
return sorted_nums
```
其中,a、b、c分别为三个整数,sort_three_nums_desc()函数返回按照从大到小排序后的结果。例如,sort_three_nums_desc(3, 1, 5)将返回[5, 3, 1]。
相关问题
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://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)