python怎么看三角形_Python判斷三角形

#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")

運行結果如下:

f429553501d70bef8aa978ac17cbaa5c.png

注:在這注意的是條件表達式中使用and運算符,而不是&!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值