python输入三个人身高判断并输出三个人中谁最高
时间: 2023-05-11 20:02:23 浏览: 89
可以使用以下代码实现:
```python
heights = []
for i in range(3):
height = float(input("请输入第%d个人的身高:" % (i+1)))
heights.append(height)
max_height = max(heights)
if heights.count(max_height) == 1:
index = heights.index(max_height)
print("第%d个人最高,身高为%.2f米。" % (index+1, max_height))
else:
print("三个人身高相同,均为%.2f米。" % max_height)
```
这段代码会让用户输入三个人的身高,然后判断并输出最高的那个人的编号和身高。如果三个人身高相同,则输出三个人的身高均为多少。
相关问题
python 输入三角形三条边判断能否组成三角形计算三角形面积并输出
好的,可以使用以下代码实现:
```python
a = float(input("请输入三角形第一条边的长度:"))
b = float(input("请输入三角形第二条边的长度:"))
c = float(input("请输入三角形第三条边的长度:"))
if a + b > c and a + c > b and b + c > a: # 判断能否组成三角形
p = (a + b + c) / 2 # 计算半周长
area = (p * (p - a) * (p - b) * (p - c)) ** 0.5 # 计算面积
print("可以组成三角形,三角形面积为:", area)
else:
print("无法组成三角形")
```
运行示例:
```
请输入三角形第一条边的长度:3
请输入三角形第二条边的长度:4
请输入三角形第三条边的长度:5
可以组成三角形,三角形面积为: 6.0
```
python输入并输出中文字符串并判断是否相同
可以使用input()函数输入中文字符串,使用print()函数输出中文字符串,然后使用==运算符判断两个字符串是否相同。需要注意的是,在字符串前面加上 "u" 表示这是一个 Unicode 字符串,以避免出现编码问题。
示例代码如下:
```python
# 输入中文字符串1
str1 = input(u"请输入中文字符串1:")
# 输入中文字符串2
str2 = input(u"请输入中文字符串2:")
# 判断两个字符串是否相同
if str1 == str2:
print(u"两个字符串相同")
else:
print(u"两个字符串不同")
```
当然,如果你需要比较中文字符串时忽略大小写,可以将两个字符串都转换为小写或大写,然后再进行比较。例如:
```python
if str1.lower() == str2.lower():
print(u"两个字符串相同")
else:
print(u"两个字符串不同")
```
相关推荐
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)