用户输入3个实数,输出其中最大值
时间: 2024-02-21 11:33:01 浏览: 20
以下是Python代码实现:
```python
a = float(input("请输入第1个实数:"))
b = float(input("请输入第2个实数:"))
c = float(input("请输入第3个实数:"))
if a >= b and a >= c:
print("最大值为:", a)
elif b >= a and b >= c:
print("最大值为:", b)
else:
print("最大值为:", c)
```
首先,我们使用 `float()` 函数将用户输入的字符串转换成实数类型。然后,使用 `if-elif-else` 结构来比较三个实数的大小。如果第一个实数 `a` 大于等于第二个实数 `b` 并且大于等于第三个实数 `c`,则 `a` 是最大值;如果第二个实数 `b` 大于等于第一个实数 `a` 并且大于等于第三个实数 `c`,则 `b` 是最大值;否则,第三个实数 `c` 是最大值。最后,使用 `print()` 函数输出最大值。
相关问题
用户输入三个实数,输出其中值最大的一个。
可以使用以下代码实现:
a = float(input("请输入第一个实数:"))
b = float(input("请输入第二个实数:"))
c = float(input("请输入第三个实数:"))
if a >= b and a >= c:
print("最大值为:", a)
elif b >= a and b >= c:
print("最大值为:", b)
else:
print("最大值为:", c)
Python代码 用户输入三个实数,输出其中值最大的一个。
以下是实现该功能的 Python 代码:
```python
num1 = float(input("请输入第一个实数:"))
num2 = float(input("请输入第二个实数:"))
num3 = float(input("请输入第三个实数:"))
if num1 >= num2 and num1 >= num3:
print("最大值是:", num1)
elif num2 >= num1 and num2 >= num3:
print("最大值是:", num2)
else:
print("最大值是:", num3)
```
用户可以依次输入三个实数,程序会比较它们的大小,并输出其中的最大值。