Python 通过创建MyMath类计算圆的周长面积球的表面积体积

Python 通过创建MyMath类计算圆的周长面积球的表面积体积

import math
class MyMath:
    def __init__(self,r,):
        self.r=r
    def C(self):
        c = 2 * math.pi * self.r
        return c
    def area(self):
        a=math.pi*r*r
        return a
    def volume(self):
        v=(4/3)*math.pi*r*r*r
        return v
    def surfaceArea(self):
        s=4*math.pi*r*r
        return s
r=int(input("请输入圆的半径:"))
p=MyMath(r)
print("圆的周长={0:0.2f}".format(p.C()))
print("圆的面积={0:0.2f}".format(p.area()))
print("球的表面积={0:0.2f}".format(p.surfaceArea()))
print("球的体积={0:0.2f}".format(p.volume()))

结果截图:
Python 通过创建MyMath类计算圆的周长面积球的表面积体积_第1张图片

你可能感兴趣的:(python)