这篇文章主要介绍了Python判断三段线能否构成三角形的代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
我就废话不多说了,还是直接看代码吧!
#!/usr/bin/env python3 #coding = utf-8 def is_triangle(a=0, b=0, c=0): #abc 三条边长 A = <em style="color:transparent">来源[email protected]搞@^&代*@码)网</em>[a,b,c] A.sort() #升序排序 if A[2] </div><p><span style="color: #ff0000"><strong>补充知识:</strong></span><strong>python编程:判断输入的边长能否构成三角形 如果能则计算出三角形的周长和面积</strong></p><p>看代码吧!</p><div class="gaodaimacode"><pre class="prettyprint linenums"> 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()
以上就是Python判断三段线能否构成三角形的代码的详细内容,更多请关注gaodaima搞代码网其它相关文章!