Case Study: Building Software in Python
Mark Pedigo, PhD
Principal Data Scientist
BasicCalculator
FinancialCalculator
BasicCalculator
MortgageCalculator
FinancialCalculator
def MortgageClass(FinancialCalculator):
"""
MortgageClass extends the FinancialCalculator to mortgage specific calculations.
"""
...
class MortgageCalculator(FinancialCalculator):
def __init__(self, loan_amount, annual_interest_rate, years):
super().__init__()
self.loan_amount = loan_amount
self.monthly_interest_rate = self.monthly_interest(annual_interest_rate)
self.months = years * 12
# Create an attribute to hold the monthly payment amount.
self.monthly_payment = self.calculate_monthly_payment()
dir(ClassName)
to get a list of the functions of a classdir(MortgageCalculator)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__',
'__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__',
'__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__',
'difference', 'monthly_interest', 'months_from_years',
'power', 'product', 'quotient', 'sum']
Case Study: Building Software in Python