补充代码:下列代码中,定义了一个矩形类Retangle
class Retangle:width = 10
height = 15
def__init__(self, width=0, height=0):
self.width = width
self.height = height
defget_size(self):
self.width = 获取用户从键盘输入的宽度数值
self.height = 获取用户从键盘输入的高度数值
defget_area(self):
return 计算矩形面积
print(' Retangle.width = ', 访问类属性width )
rect = Retangle( )
rect.get_size( )
print('width = ', 访问实例的宽度属性值 )
print('height = ', 访问实例的高度属性值 )
print('area = ', 访问get_area实例方法 )
你的问题呢,如果是单纯补充代码课后作业答案应该都有吧
参考参考:
class Retangle:
width = 10
height = 15
def __init__(self, width=0, height=0):
self.width = width
self.height = height
def get_size(self):
self.width = float(input('输入的宽度数值 :'))
self.height = float(input('输入的高度数值 :'))
def get_area(self):
return self.width * self.height
print(' Retangle.width = ', Retangle.width)
rect = Retangle()
rect.get_size()
print('width = ', rect.width)
print('height = ', rect.height)
print('area = ', rect.get_area())
页:
[1]