导语:
本文主要介绍了关于python怎么计算面积?的相关知识,包括用python计算长方形面积的代码,以及python计算球体表面积和体积这些编程知识,希望对大家有参考作用。
用Python计算面积的知识点:
1.矩形的面积和三角形的面积,因为要从终端接收用户的多个参数输入,使用map(int, raw_input().split())方法
2. 圆面积只想保留小数点后两位,就用到了 %.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 OpenCV图像处理01/11
- ♥ python有哪些进阶书籍11/21
- ♥ python 中的 gRPC 是什么?11/29
- ♥ 判断python字典中key是否存在的两种方法10/01
- ♥ python如何处理捕获的异常11/11
- ♥ python中的等号是什么意思?09/03
内容反馈