Python3如何判断三角形的类型

这篇文章主要介绍了Python3如何判断三角形的类型,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

# 判断三角形类型

 def triangle(a,b,c): if a>0 and b>0 and c>0: if a+b>c and b+c>a and a+c>b: if a == b and b == c: return ("这是等边三角形") elif a == b or b == c or c == a: return("这是等腰三角形") else: return("这是不规则三角形") elif a+b==c or b+c==a or a+c==b: return("这是个直角三角形") else: return('这好像不是个三角形') else: return("请输入大于0的数字")

补充知识:python:输入三个数判断是什么三角形

刚刚学习Python,欢迎大家指点

 #Filename:Triangle #Function:Judgment triangle #Author:Judy #Time:2018.9.26 a=int(input("Please input the first side:"))  #输入第一条边 b=int(input("Please input the second side:"))  #输入第二条边 c=int(input("Please input the third side:"))  #输入第三条边 if (a+b>c) and (a+c>b) and (b+c>a):        #判断是否是三角形 if a==b==c: print("This is a equilateral triangle") #等边三角形 elif (a==b or a==c or b==c): print("This is a isosceles triangle")  #等腰三角形 elif (a*a+b*b==c*c) or (a*a+b*b==c*c) or (a*a+b*b==c*c): print("This is a right triangle")    #直角三角形 else: print("This is a scalene triangle")   #不规则三角形 else : print("This isn't a triangle")       #不是三角形 

注意点:不能直接使用a=input(),输入3,用a=input(),a=‘3',类型为string类型,不能进行相乘

使用[a,b,c]元组进行输入,不能直接转换成int,因为元组最多只能int两个参数

以上这篇Python3如何判断三角形的类型就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持html中文网。

以上就是Python3如何判断三角形的类型的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python