温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python3判断三角形类型的方法

发布时间:2020-08-04 10:57:34 来源:亿速云 阅读:533 作者:小猪 栏目:开发技术

这篇文章主要讲解了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的数字")

Python3判断三角形类型的方法

Python3判断三角形类型的方法

补充知识: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判断三角形类型的方法有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI