python判断三角形是否成立_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的数字")

742fe95706625fa0b56f03b1098d2479.png

6ed268a683a6368ec5d6b992ef5fa851.png

补充知识: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如何判断三角形的类型就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持聚米学院。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值