输入三个整数,把这三个整数按从大到小的顺序输出。方法不限
时间: 2024-03-30 18:15:00 浏览: 10
以下是 Python 代码实现:
```python
a, b, c = map(int, input("请输入三个整数,用空格隔开:").split())
# 方法一:使用列表的 sort 方法
lst = [a, b, c]
lst.sort(reverse=True)
print(lst)
# 方法二:使用内置函数 sorted 函数
lst = sorted([a, b, c], reverse=True)
print(lst)
# 方法三:使用条件判断语句
if a >= b and a >= c:
if b >= c:
print(a, b, c)
else:
print(a, c, b)
elif b >= a and b >= c:
if a >= c:
print(b, a, c)
else:
print(b, c, a)
else:
if a >= b:
print(c, a, b)
else:
print(c, b, a)
```
以上代码中,使用了三种不同的方法实现三个整数从大到小的排序。其中,方法一和方法二都是通过调用列表自带的排序函数实现的,方法三则是通过条件判断语句实现的。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)