用Python编写关于计算图形面积的代码实现,供大家参考,具体内容如下
#寒假打卡28天第7天
import math
class Round(): #圆形
def __init__(self, R):
self.R = R
def area(self):
return self.R * self.R * 3.14
def girth(self):
return self.R * 2 * 3.14
class Rectangle():#矩形
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
def girth(self):
return self.length + self.width
class Triangle():#三角形
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
def area(self):
l = (self.a + self.b + self.c)/2
return round(math.sqrt(l * (l - self.a) * (l - self.b) * (l - self.c)), 2) #round保留2为小数
def girth(self):
return self.a + self.c + se