AttributeError
class Point(object):
def __init__(self, x,y):
self.x = x
self.y = y
def string(self):
print('X:{0},Y:{1}'.format(self.x,self.y))
class Circle(Point):
def __init__(self, x, y,radius):
super().__init__(x,y)
self.radius = radius
def string(self):
print('该图形初始化点为:X:{0},Y:{1};半径为:{2}'.format(self.x,self.y,self.radius))
class Size(object):
def __init__(self, width, height):
self.width = width
self.height = height
def string(self):
print('Width:{0},Height:{1}'.format(self.width,self.height))
class Rectangle(Point,Size):
def __init__(self, x, y, width, height):
super().__init__(x,y)
super().__init__(width, height)
def string(self):
print('该图形初始化点为:X:{0},Y:{1};长宽分别为:Width:{2},Height:{3}'.format(self.x,self.y,self.width,self.height))
if __name__ == '__main__':
c = Circle(5,5,8)
c.string()
r1 = Rectangle(15,15,15,15)
r1.string()
r2 = Rectangle(40,30,11,14)
r2.string()
··················································································
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/PY/课程/2019-9-14/2-6 编程练习.py", line 29, in <module>
r1.string()
File "C:/Users/Administrator/Desktop/PY/课程/2019-9-14/2-6 编程练习.py", line 24, in string
print('该图形初始化点为:X:{0},Y:{1};长宽分别为:Width:{2},Height:{3}'.format(self.x,self.y,self.width,self.height))
AttributeError: 'Rectangle' object has no attribute 'width'
该图形初始化点为:X:5,Y:5;半径为:8
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 2727 份
- 解答问题 8160 个
想要进入Python Web、爬虫、人工智能等高薪领域,你需要掌握本阶段的Python基础知识,课程安排带你高效学习轻松入门,学完你也能听得懂Python工程师的行业梗。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星