#Copyright (c)2017, 東北大學軟件學院學生
# All rightsreserved
#文件名稱:a.py
# 作 者:孔雲
#問題描述:編寫程序,從鍵盤輸入三條邊,判斷是否能夠構成一個三角形。
#問題分析:組成三角形的條件是任意兩邊之和大於第三邊,如果條件成立,則能構成三角形。條件表達式中的多個條件必須全部成立,條件之間使用and運算符連接。代碼如下:
side1=float(input("the first side of triangle:"))
side2=float(input("the second side of triangle:"))
side3=float(input("the thrid side of triangle:"))
if(side1+side2>side3)and(side2+side3>side1)and(side3+side1>side2):
print (side1,side2,side3,"is sides of triangle")
else:
print (side1,side2,side3,"is not sides of triangle")
運行結果如下:
注:在這注意的是條件表達式中使用and運算符,而不是&!!!