8 Feb 2015

Minimum Monthly Payment of Credit Card using Bisection Search

#Python

'''
Program to calculate minimum Monthly Payment of a Credit Card using Bisection Search
'''

balance = 320000
annualInterestRate = 0.2
newbalance=balance
i=1
monthlyInterestRate=annualInterestRate/12.0
lowerb=newbalance/12.0
upperb=(newbalance *(1+monthlyInterestRate)**12)/12.0
minimumMonthlyPay=(lowerb+upperb)/2.0
while(i<=12):
    monthlyUnpaidBal=newbalance-minimumMonthlyPay
    newbalance=monthlyUnpaidBal+monthlyInterestRate*monthlyUnpaidBal
    i+=1     
 
    if(i==13 and round(newbalance,2)>0.00):
        i=1
        lowerb=minimumMonthlyPay

        minimumMonthlyPay=(lowerb+upperb)/2.0
        newbalance=balance
    elif(i==13 and round(newbalance,2)<0.00):
        i=1
        upperb=minimumMonthlyPay
        minimumMonthlyPay=(lowerb+upperb)/2.0
        newbalance=balance      
   
print "Lowest Payment:", round(minimumMonthlyPay,2)

Categories: , , , ,

0 comments:

Post a Comment

Copyright © UPgradeCODING | Powered by Blogger