For problem set 1c how are you guys determining how much the balance you have to pay off for the year is including interest. I feel like I am missing something that would make this easier.
```
inputBal = float(raw_input("Enter the outstanding balance on your credit card: "))
annualIR= float(raw_input("Enter the annual credit card interest rate as a decimal: "))
monthlyIR=annualIR/12
epsilon = .01
ll=inputBal/12
ul=(inputBal*((1+monthlyIR)**12))/12
##minmonthpay = (ul+ll)/2
minmonthpay = 1
totalinterest=0
month = 1
while month<=12 and inputBal-(minmonthpay*month)+totalinterest>0:
interest = (inputBal-(minmonthpay*month)+totalinterest)*monthlyIR
totalinterest = totalinterest+interest
print interest
month+=1
balance = inputBal+totalinterest
print "bal " , balance
while abs(minmonthpay*12-balance)>=epsilon:
print "remaining ", minmonthpay*12-balance
print "mp " , minmonthpay
if minmonthpay*12>balance:
print "larger"
ul = minmonthpay
print "limits ", ll , ul
minmonthpay = (ll+ul)/2
print "after adjustment mmp = ", minmonthpay
if minmonthpay*12
How much is slightly? Try starting with ll = 0 and ul = balance
It was off by over 100 The problem wasn't with the limits but rather the balance is wrong. By using some print statements it was finding the correct monthly payment but for the wrong balance.
It's fixed?
No its not fixed I still can't figure out what im doing wrong to get the wrong balance.
I think you better simplify your code by calculating the remaining balance each time you have a new mmp(minimum monthly payment).It's easier to deal with a single variable.Also you can get rid of the first while loop, you get the same result without it.If my comment wasn't helpful then please let me know.I can send you a piece of code if necessary.
Comments in your code always help - at least it helps me understand what you intended for the commented part to do.
It helps to write down on paper the process needed to solve the problem - this can lead to a sort of outline for your code/algorithm. You are using bisection search to find the minimum payment to pay off a loan (within one cent) in twelve months. You are using while loops to run through 12 months of payments and interest If the balance at the end of the loop doesn't match your criteria, you adjust the payment. A good place to start might be making sure that your while loop conditions are correct. Have you been exposed to functions yet?
You have definitely made your loop of 12 monthly payments too complicated. From page six of the instructions: ``` Updated balance each month = Previous balance * (1 + Monthly interest rate) – Minimum monthly payment ``` Consider using a for loop instead - run through twelve months of interest and payments updating balance each month: ``` for month in range(12): balance = balance * (1 + monthlrIR) - minmonthpay ``` I think there are other problems that might not be clear till after you get the 12 months of payment loops fixed. Like - at the top of the bisection loop, you are basically starting over because the last monthly payment didn't work. Since you are starting over, you need to re-initialize balance at the top of this loop (because you changed it last time around). It is probably a matter of preference but when printing out variables for debugging I like to put related things on the same line - it cuts down on the number of lines you have to look at when trying to figure it out. http://dpaste.com/1414386/
Join our real-time social learning platform and learn together with your friends!