| 
 | 
 
 
发表于 2021-6-14 13:37:31
From FishC Mobile
|
显示全部楼层
|阅读模式
 
 
 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
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 =       获取用户从键盘输入的宽度数值                       
    self.height =       获取用户从键盘输入的高度数值                     
def  get_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())
 
  复制代码 
 
 
 |   
 
 
 
 |