新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎么計(jì)算面積?
用python計(jì)算面積的知識(shí)點(diǎn):

1、 長方形面積和三角形面積,因?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") 網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:python怎么計(jì)算面積?
分享鏈接:http://m.fisionsoft.com.cn/article/cocdoso.html


咨詢
建站咨詢
