欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

Python3如何判断三角形的类型

时间:2021-01-19 12:06:29|栏目: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两个参数

上一篇:在Python的Bottle框架中使用微信API的示例

栏    目:Python代码

下一篇:python判断字符串或者集合是否为空的实例

本文标题:Python3如何判断三角形的类型

本文地址:http://www.codeinn.net/misctech/47622.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有