网络编程
位置:首页>> 网络编程>> Python编程>> Python判断三段线能否构成三角形的代码

Python判断三段线能否构成三角形的代码

作者:贾贝贝  发布时间:2023-01-21 19:44:25 

标签:Python,三段线,三角形

我就废话不多说了,还是直接看代码吧!


#!/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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com