输入a,b,c,降序排列,python
时间: 2023-05-23 10:05:42 浏览: 64
代码如下:
```
a = input("请输入a:")
b = input("请输入b:")
c = input("请输入c:")
list_num = [a, b, c]
list_num.sort(reverse=True)
print("降序排列结果为:", list_num)
```
输入a、b、c三个数字后,程序会将它们存储在一个列表中,使用`sort()`方法进行降序排列,最后输出排序结果。
相关问题
输入 abc 三个数,按照降序排列
A:可以按照以下方式实现:
```python
a, b, c = input("请输入三个数,用空格分隔: ").split()
a, b, c = float(a), float(b), float(c) # 将输入的字符串转换成浮点数
if a >= b and b >= c:
print(a, b, c)
elif a >= c and c >= b:
print(a, c, b)
elif b >= a and a >= c:
print(b, a, c)
elif b >= c and c >= a:
print(b, c, a)
elif c >= a and a >= b:
print(c, a, b)
else:
print(c, b, a)
```
输入示例:
```
请输入三个数,用空格分隔: 5 9.8 1.2
```
输出示例:
```
9.8 5.0 1.2
```
python输入三个数按降序输出
好的,下面是代码实现:
```python
a, b, c = map(int, input("请输入三个数,以空格隔开:").split())
if a >= b:
if b >= c:
print(a, b, c)
elif a >= c:
print(a, c, b)
else:
print(c, a, b)
else:
if a >= c:
print(b, a, c)
elif b >= c:
print(b, c, a)
else:
print(c, b, a)
```
以上代码首先通过 `map` 函数将输入的字符串转换为三个整数,并使用 `split` 方法以空格为分隔符进行拆分。然后根据三个数的大小关系,使用嵌套的 `if` 语句进行判断,最终输出降序排列的三个数。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)