모기지 계산기 클래스 만들기
여러분은 기본 사칙연산을 수행하는 BasicCalculator부터 시작했어요.
그다음 이 BasicCalculator를 상속하는 FinancialCalculator를 만들고, 연 이자율을 기준으로 월 이자를 계산하는 메서드 monthly_interest()를 추가해 기능을 확장했어요.
이제 MortgageCalculator 클래스를 만들어 볼 차례예요!
이 연습은 강의의 일부입니다
케이스 스터디: Python으로 소프트웨어 만들기
연습 안내
- 부모 클래스를 이름으로 부르지 않고 부모의 메서드와 속성을 인스턴스화하세요.
- 적절한 매개변수를 사용해
self.loan_amount를 초기화하세요. - 상속받은 메서드를 사용해
self.monthly_interest_rate를 초기화하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
class MortgageCalculator(FinancialCalculator):
def __init__(self, loan_amount, annual_interest_rate, years):
# Initialize the parent attributes and functions
____
# Initialize the loan_amount attribute
self.loan_amount = ____
# Initialize the monthly_interest_rate
self.monthly_interest_rate = self.____(annual_interest_rate)