Get startedGet started for free

Create the mortgage calculator class

You started with a BasicCalculator that performed basic arithmetic.

You then created a FinancialCalculator which inherited from this BasicCalculator. You extended this class by adding a method, monthly_interest(), that calculates the monthly interest given the annual interest rate.

Now it's time to create the MortgageCalculator class!

This exercise is part of the course

Case Study: Building Software in Python

View Course

Exercise instructions

  • Instantiate the parent methods and attributes without invoking the parent by name.
  • Initialize self.loan_amount using the appropriate parameter.
  • Use an inherited method to initialize self.monthly_interest_rate.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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)
Edit and Run Code