python3 練手實例1 計算三角形周長和面積


 1 def j():
 2     a,b,c=map(float,input('請輸入三角形三條邊的長度,用空格隔開:').split())
 3     if a>0 and b>0 and c>0 and a+b>c and a+c>b and b+c>a:
 4         l=a+b+c
 5         p=l/2
 6         s=p*(p-a)*(p-b)*(p-c)#海倫公式
 7         print('三角形的周長:{:.2f}\n三角形的面積:{:.2f}'.format(l,s))
 8     else:
 9         print('三角形不成立,請重新輸入')
10         j()
11 j()  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM