MITx 6.00.1x Calculating Interest rate

92 Views Asked by At

So, I'm having a lot of trouble inputting my answer into the grader for the MIT Intro to CS in Python course on edX.

The specific problem ask for a program that will calculate the interest on a credit card given the monthly payment rate, interest rate, and initial balance.

I'm pretty sure my code is fine, I just can't get the grader to accept it.

I've tried changing the code to account for the names of the variables that the grader wants and removed the input prompts, function wrapper and return calls, but it still doesn't work.

Here is my initial code:

from math import *
b = float(input("balance = "))
r = float(input("annualInterestRate = "))
p = float(input("monthlyPaymentRate = "))
bval = []


def interest(b, r, p):

    bal = (b - (b * p))

    def update(bal, r):
        balance = (bal + (r / 12.0) * bal)
        return balance

    if len(bval) < 12:
        bval.append(update(bal, r))
        return(interest(bval[-1], r, p))
    elif len(bval) == 12:
        return print("Remaning balance: " + "{:.2f}".format(bval[-1]))


interest(b, r, p)

And here is what it was modified to:

from math import *
bval = []

bal = (blance - (balance * monthlyPaymentRate))
def update(balance, annualInterestRate):
    bal = round((balance + (annualInterestRate / 12.0) * balance), 2)
    return bal

if len(bval) < 12:
    bval.append(update(bal, annualInterestRate))
    (interest(bval[-1], annualInterestRate, monthlyPaymentRate))
elif len(bval) == 12:
    print("Remaning balance: " + "{:.2f}".format(bval[-1]))

Any help?

0

There are 0 best solutions below