Python3如何判断三角形的类型

作者:Winnie~ 时间:2022-01-06 22:12:51 

# 判断三角形类型


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两个参数

来源:https://www.cnblogs.com/test123/p/10084179.html

标签:Python3,三角形,类型
0
投稿

猜你喜欢

  • Instr函数与InstrRev函数的区别

    2008-07-07 16:53:00
  • 缓存是如何实现的?

    2009-11-01 15:35:00
  • 使用Python编写一个简单的tic-tac-toe游戏的教程

    2021-01-26 04:27:43
  • oracle下加密存储过程的方法

    2009-02-28 10:50:00
  • Python入门教程(二十二)Python的类和对象

    2021-11-22 06:00:56
  • 看ASP程序源码的方法及工具

    2009-01-21 19:58:00
  • asp如何通过表单创建一个Word?

    2010-06-07 20:56:00
  • 经验总结:修改MySQL默认密码的具体步骤

    2009-01-04 13:29:00
  • python合并文本文件示例

    2021-05-08 01:24:49
  • 使用python爬取taptap网站游戏截图的步骤

    2021-09-17 07:44:34
  • python正则表达式中匹配次数与贪心问题详解(+ ?*)

    2021-04-24 20:52:04
  • PHP PDOStatement::fetch讲解

    2023-06-04 20:06:02
  • Python + Tkinter连接本地MySQL数据库简单实现注册登录

    2023-04-24 22:07:07
  • 深入理解Python虚拟机中描述器的实现原理

    2021-08-05 21:20:48
  • 网站数据库,是选SQL Server还是Access好

    2008-05-23 13:19:00
  • python列表切片和嵌套列表取值操作详解

    2021-07-23 21:54:30
  • Python语言基础之函数语法

    2021-11-06 23:18:44
  • ASP程序与SQL存储过程结合使用详解

    2011-03-25 10:50:00
  • FF下,用 col 隐藏表格列的方法详解!

    2008-04-02 11:35:00
  • 浅析python打包工具distutils、setuptools

    2021-03-30 14:45:14
  • asp之家 网络编程 m.aspxhome.com