高普考題庫
108 年 108年公務人員高等考試三級考試暨普通考試・程式語言
申論 4下列Python 程式的執行結果為何?(15 分)class Shape:def __init__(self, x, y):self.x = xself.y = yself.description = "unknown"def area(self):return self.x * self.ydef perimeter(self):return 2 * self.x + 2 * self.ydef describe(self, text):self.description = textclass Square(Shape):def __init__(self, x):self.x = xself.y = xclass DoubleSquare(Square):def __init__(self, y):self.x = 2 * yself.y = ydef perimeter(self):return 2 * self.x + 3 * self.yrectangle = Shape(100, 45)print(rectangle.perimeter())dictionary = {}dictionary["DoubleSquare"] = DoubleSquare(5)dictionary["Rectangle"] = Shape(600,45)dictionary["Square"] = Square(20)print(dictionary["Square"].area())dictionary["DoubleSquare"].describe("Double square")print(dictionary["Rectangle"].description)