Q284. 클래스의 메소드 오버라이딩을 이용하여 정사각형의 둘레와 면적을 구하는 프로그램을 완성하시오. (700점)
class Rectangle():
def ________(self, width, height):
self.width = width
self.height = height
def length(self) :
print("사각형 둘레 :", self.width*2 + self.height*2)
def area(self):
print("직사각형 면적 :", self.width * self.hegiht)
class Square(_________):
def ________(self, a):
super().__init__(a, a)
def area(self):
print("정사각형 면적 :", pow(self.width, 2))
s = ________(10)
s.length()
s.area()
- 난이도(1~10) : 7
- 힌트 :
- - 실행 결과
-
사각형 둘레 : 40
정사각형 면적 : 100
class Rectangle():
def __init__(self, width, height):
self.width = width
self.height = height
def length(self) :
print("사각형 둘레 :", self.width*2 + self.height*2)
def area(self):
print("직사각형 면적 :", self.width * self.hegiht)
class Square(Rectangle):
def __init__(self, a):
super().__init__(a, a)
def area(self):
print("정사각형 면적 :", pow(self.width, 2))
s = Square(10)
s.length()
s.area()