返回

init-Python公式错误消息;Fixed()不接受参数

发布时间:2022-09-07 09:02:02 360
# node.js
def findPayment(loan, r, m):
    """Assumes: loan and r are floats, m an int
    Returns the monthly rate of r for m months"""
    return loan*((r*(1+r)**m)/((1+r)**m - 1))

class Mortgage(object):
    """Abstract class for building different kinds of mortgages"""
    def _init_(self, loan, annRate, months):
        """"Assumes: loan and annRate are floats, months an int
        Creates a new mortagage of size loan, duration monthls, and
        annual rate annRate"""
        self.loan = loan
        self.rate = annRate/12
        self.months = months
        self.paid = [0.0]
        self.outstanding = [loan]
        self.payment = findPayment(loan, self.rate, months)
        self.legend = none #description of mortgage

    def _makePayment(self):
        """Make a payment"""
        self.paid.append(self.payment)
        reduction = self.payment - self.outstanding[-1]*self.rate
        self.outstanding.append(self.outstanding[-1] - reduction)
        
    def getTotalPaid(self):
        """Return the total amount paid so far"""
        return sum(self.paid)
    
    def _str_(self):
        return self.legend

class Fixed(Mortgage):
    def _init_(self, loan, r, months):
        Mortgage._init_(self, loan, r, months)
        self.legend = 'Fixed, ' + str(round(r*100, 2)) + '%'

class FixedWithPts(Mortgage):
    def _init_(self, loan, r, months, pts):
        Mortgage._init_(self, loan, r, months)
        self.pts = pts
        self.paid = [loan*(pts/100)]
        self.legend = 'Fixed,' + str(round(r*100,2)) + '%, ' + str(pts) + ' points'

class TwoRate(Mortgage):
    def _init_(self, loan, r, months, teaserRate, teaserMonths):
        Mortgage._init_(self, loan, teaserRate, months)
        self.teaserMonths = teaserMonths
        self.teaserRate = teaserRate
        self.nextRate = teaserRate
        self.nextRate =  r/12
        self.legend = str(teaserRate*100) + '%for' + str(self.teaserMonths) + 'months, then' + str(round(r*100,2)) + '%'

    def makePayment(serlf):   
        if len(self.paid) == self.teaserMonths + 1:
            self.rate = self.nextRate
            self.payment = findPayment(self.outstanding[-1],
                                      self.rate,
                                      self.months - self.teaserMonths)            
        Mortgage.makePayement(self)

def compareMortgages(amt, years, fixedRate, pts, ptsRate, varRate1, varRate2, varMonths):
    totMonths = years*12
    fixed1 = Fixed(amt, fixedRate, totMonths)
    fixed2 = FixedWithPts(amt, ptsRate, totMonths, pts)
    twoRate = TwoRate(amt,  ptsRate, totMonths, pts)
    twoRate = TwoRate(amt, varRate2, totMonths, varRate1, varmonths)
    morts = [fixed1, fixed2, twoRate]
    for m in range(totMonths):
    for mort in morts:
    mort.makepayment()
    for m in morts:
    print(m)
    print('Total Payments = $' + str(int(m.getTotalPaid())))

compareMortgages(amt=200000, years=30, fixedRate=0.07,
    pts = 3.25, ptsRate=0.05, varRate1=0.045,
    varRate2=0.095, varMonths=48)
TypeError                                 Traceback (most recent call last)
C:\Users\NICKMO~1\AppData\Local\Temp/ipykernel_48996/48896394.py in 
     78             print('Total Payments = $' + str(int(m.getTotalPaid())))
     79
---> 80 compareMortgages(amt=200000, years=30, fixedRate=0.07,
     81                 pts = 3.25, ptsRate=0.05, varRate1=0.045,
     82                 varRate2=0.095, varMonths=48)

C:\Users\NICKMO~1\AppData\Local\Temp/ipykernel_48996/48896394.py in compareMortgages(amt, years, fixedRate, pts, ptsRate, varRate1, varRate2, varMonths)
     66                     varRate1, varRate2, varMonths):
     67     totMonths = years*12
---> 68     fixed1 = Fixed(amt, fixedRate, totMonths)
     69     fixed2 = FixedWithPts(amt, ptsRate, totMonths, pts)
     70     twoRate = TwoRate(amt,  ptsRate, totMonths, pts)

TypeError: Fixed() takes no arguments
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像