python判断三角形类型的代码

编程入门 行业动态 更新时间:2024-10-22 07:40:38

python判断三<a href=https://www.elefans.com/category/jswz/34/1769024.html style=角形类型的代码"/>

python判断三角形类型的代码

# 判断三角形类型

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

更多推荐

python判断三角形类型的代码

本文发布于:2024-02-26 06:39:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1701629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角形   类型   代码   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!