Python 计算三角形面积的方法
1、1给出程序解读,定义一个计算三角形面积的方法,并应用@property将其转换为属性,最后创建类的实例,并访问转换后的属性。

3、3在__init__()方法中定义实例属性。def __init__(self, width, height):#在__init__()方法中定义实例属性。 self.width = width#三角形的底 self.height = height#三角形的高

5、5计算机三角形的面积的方法;def area(self):#计算机三角形的面积的方法 return self.width * self.height*0.5#返回三角形面积的方法

7、7输出属性的值。print('面积为:', triangles.area) #输出属性的值。
