Python3如何判斷三角形的類型
更新時間:2020年04月12日 11:47:12 作者:Winnie~
這篇文章主要介紹了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("這是不規(guī)則三角形") elif a+b==c or b+c==a or a+c==b: return("這是個直角三角形") else: return('這好像不是個三角形') else: return("請輸入大于0的數(shù)字")
補充知識:python:輸入三個數(shù)判斷是什么三角形
剛剛學(xué)習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") #不規(guī)則三角形 else : print("This isn't a triangle") #不是三角形
注意點:不能直接使用a=input(),輸入3,用a=input(),a=‘3',類型為string類型,不能進行相乘
使用[a,b,c]元組進行輸入,不能直接轉(zhuǎn)換成int,因為元組最多只能int兩個參數(shù)
以上這篇Python3如何判斷三角形的類型就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python實現(xiàn)簡單的ui界面的設(shè)計步驟(適合小白)
當我們書寫一個python程序時,我們在控制臺輸入信息時,往往多有不便,并且為了更加美觀且直觀的方式輸入控制命令,我們常常設(shè)計一個ui界面,這樣就能方便執(zhí)行相關(guān)功能,如計算器、日歷等界面,本博客是為了給ui設(shè)計的小白進行講解,需要的朋友可以參考下2024-07-07Python subprocess模塊學(xué)習總結(jié)
從Python 2.4開始,Python引入subprocess模塊來管理子進程,以取代一些舊模塊的方法:如 os.system、os.spawn*、os.popen*、popen2.*、commands.*不但可以調(diào)用外部的命令作為子進程,而且可以連接到子進程的input/output/error管道,獲取相關(guān)的返回信息2014-03-03