编写函数,判断三个数能否构成一个三角形(直角三角形,等腰三角形,等边三角形还是普通三角形)。
时间: 2024-05-09 12:19:07 浏览: 12
```python
def is_triangle(a, b, c):
# 判断是否能组成三角形
if a + b > c and a + c > b and b + c > a:
# 判断是否为等边三角形
if a == b == c:
return "等边三角形"
# 判断是否为等腰三角形
elif a == b or a == c or b == c:
# 判断是否为直角三角形
if a ** 2 + b ** 2 == c ** 2 or a ** 2 + c ** 2 == b ** 2 or b ** 2 + c ** 2 == a ** 2:
return "直角等腰三角形"
else:
return "等腰三角形"
# 判断是否为直角三角形
elif a ** 2 + b ** 2 == c ** 2 or a ** 2 + c ** 2 == b ** 2 or b ** 2 + c ** 2 == a ** 2:
return "直角三角形"
else:
return "普通三角形"
else:
return "不能构成三角形"
# 测试
print(is_triangle(3, 4, 5)) # 直角三角形
print(is_triangle(3, 3, 3)) # 等边三角形
print(is_triangle(3, 4, 4)) # 等腰三角形
print(is_triangle(5, 5, 8)) # 直角等腰三角形
print(is_triangle(3, 4, 7)) # 不能构成三角形
```
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)