class mortgage(object)"""abstract class for building different kinds of mortgages""def __init__(selfloanannratemonths)"""create new mortgage""self loan loan self rate annrate/ self months months self paid [ self owed [loanself payment findpayment(loanself ratemonthsself legend none #description of mortgage def makepayment(self)"""make payment""self paid append(self paymentreduction self payment self owed[- ]*self rate self owed append(self owed[- reductiondef gettotalpaid(self)"""return the total amount paid so far""return sum(self paiddef __str__(self)return self legend def plotpayments(selfstyle)pylab plot(self paid[ :]stylelabel self legenddef plotbalance(selfstyle)pylab plot(self owedstylelabel self legenddef plottotpd(selfstyle)"""plot the cumulative total of the payments made""totpd [self paid[ ]for in range( len(self paid))totpd append(totpd[- self paid[ ]pylab plot(totpdstylelabel self legenddef plotnet(selfstyle)"""plot an approximation to the total cost of the mortgage over time by plotting the cash expended minus the equity acquired by paying off part of the loan""totpd [self paid[ ]for in range( len(self paid))totpd append(totpd[- self paid[ ]#equity acquired through payments is amount of original loan paid to datewhich is amount of loan minus what is still owed equityacquired pylab array([self loan]*len(self owed)equityacquired equityacquired pylab array(self owednet pylab array(totpdequityacquired pylab plot(netstylelabel self legendfigure class mortgage with plotting methods the expression pylab array(self owedin plotnet performs type conversion thus farwe have been calling the plotting functions of pylab with arguments of type list under the coverspylab has been converting these lists to different