Python判断三段线能否构成三角形的代码
作者:贾贝贝 时间:2023-01-21 19:44:25
我就废话不多说了,还是直接看代码吧!
#!/usr/bin/env python3
#coding = utf-8
def is_triangle(a=0, b=0, c=0): #abc 三条边长
A = [a,b,c]
A.sort() #升序排序
if A[2] < A[1] +A[0]:
print("{} is triangle".format(A))
else:
print("不构成三角")
def triangle(f):
a = float(input("第一条边是 = "))
b = float(input("第二条边是 = "))
c = float(input("第三条边是 = "))
f(a, b, c)
triangle(is_triangle) # 常规函数的调用
补充知识:python编程:判断输入的边长能否构成三角形 如果能则计算出三角形的周长和面积
看代码吧!
def main():
a = float(input('a = '))
b = float(input('b = '))
c = float(input('c = '))
if a + b > c and a + c > b and b + c > a:
print('周长: %f' % (a + b + c))
p = (a + b + c) / 2
area = math.sqrt(p * (p - a) * (p - b) * (p - c))
print('面积: %f' % (area))
else:
print('不能构成三角形')
if __name__ == '__main__':
main()
来源:https://blog.csdn.net/weixin_43333826/article/details/83660095
标签:Python,三段线,三角形
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解如何在ChatGPT内构建一个Python解释器
2022-06-18 21:37:38
![](https://img.aspxhome.com/file/2023/6/117286_0s.png)
为python设置socket代理的方法
2021-09-23 16:25:34
Ubuntu20下的Django安装的方法步骤
2022-05-01 09:07:24
![](https://img.aspxhome.com/file/2023/5/81705_0s.png)
一个css与js结合的下拉菜单支持主流浏览器
2023-07-18 01:28:20
![](https://img.aspxhome.com/file/2023/1/55951_0s.gif)
javascript使用location.search的示例
2023-07-16 09:14:40
vue elementUI实现自定义正则规则验证
2024-05-28 16:00:58
![](https://img.aspxhome.com/file/2023/2/123082_0s.jpg)
高效管理http连接的方法
2022-02-16 23:12:14
![](https://img.aspxhome.com/file/2023/5/132505_0s.png)
jQuery 1.3.3 新功能[译]
2009-06-04 12:23:00
Nodejs 和Session 原理及实战技巧小结
2024-05-13 10:06:08
![](https://img.aspxhome.com/file/2023/7/125837_0s.png)
Vue简易版无限加载组件实现原理与示例代码
2024-04-28 10:54:53
![](https://img.aspxhome.com/file/2023/8/133068_0s.jpg)
python 实现体质指数BMI计算
2023-01-25 12:44:56
![](https://img.aspxhome.com/file/2023/1/110571_0s.png)
Linux下PhpMyAdmin程序目录结构的安全管理
2023-10-18 14:16:05
Python入门篇之面向对象
2023-10-19 16:31:51
关于 Flash Banner 设计的建议
2010-02-02 18:19:00
Python全局变量global关键字详解
2023-01-29 22:32:50
Python 文本文件与csv文件的读取与写入
2021-02-10 09:57:56
Python基于stuck实现scoket文件传输
2023-06-06 22:59:50
![](https://img.aspxhome.com/file/2023/5/112375_0s.png)
Python DPED机器学习之实现照片美化
2023-11-25 01:50:24
![](https://img.aspxhome.com/file/2023/5/86315_0s.jpg)
python超参数优化的具体方法
2022-01-04 22:28:31
golang 生成对应的数据表struct定义操作
2024-05-21 10:27:47