您好,登錄后才能下訂單哦!
這篇文章主要介紹python計(jì)算面積的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
用Python計(jì)算面積的知識(shí)點(diǎn):
1、 長(zhǎng)方形面積和三角形面積,因?yàn)橐獜慕K端接收用戶的多個(gè)參數(shù)輸入,所以用了map(int, raw_input().split())這種方式
2. 圓面積只想保留小數(shù)點(diǎn)后兩位,就用到了 %.2f
#!/usr/bin/python #-*-coding:utf-8 -*- name = raw_input("Please input your name here : ") if name == '': print("we don't like anonymous") else: choose = input("Which shape would you like to choose 1:Rectangle, 2:Square, 3:Triangle or 4 Round? :") if choose == 1: width, height = map(int, raw_input("Input width and height here, like 5 8 :").split()) print( "Area = %d" % (width * height)) elif choose == 2: length = input("Input width and height here, like 4:") print( "Area = %d" % length ** 2) elif choose == 3: width, height = map(int, raw_input("Input width and height here, like 5 8 :").split()) print( "Area = %d" % (width * height / 2)) elif choose == 4: diameter = input("Input diameter here like 3 :") print ("Area = %.2f" % (3.14 * (diameter / 2) ** 2)) else: print( "Invalid choose")
以上是python計(jì)算面積的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。