# 判断三角形类型

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如何判断三角形的类型就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持云海天教程。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐