
Untitled
By: a guest on
Feb 24th, 2013 | syntax:
None | size: 1.35 KB | hits: 48 | expires: Never
## ps1, prob 3
print 'Given a starting balance and interest rate, this program will calculate your minimum monthly payment,'
print 'that will pay off your balance in 12 months or less.'
balance = float(raw_input('Enter the outstanding balance on your credit card:'))
interestrate = float(raw_input('Enter the annual credit card interest rate as a decimal:'))
lowerbound=balance/12
upperbound=(balance*(1+(interestrate/12))**12)/12
payment=(lowerbound+upperbound)/2
def twelvemonth ():
global payment
global lowerbound
global upperbound
month = 0
while month <=11:
month = month + 1
if month==1:
calcbalance = balance
intowed = calcbalance*(interestrate/12)
calcbalance = calcbalance + intowed - payment
if -.12 <= calcbalance <= 0 and month == 12:
print 'Monthly payment to pay off debt in 1 year: $' + str(round(payment, 2))
print 'Number of months needed: ' + str(month)
print 'Balance: $' + str(round(calcbalance, 2))
if calcbalance < -.12 and month == 12:
upperbound=payment
payment=(payment+lowerbound)/2
twelvemonth ()
if calcbalance > 0 and month == 12:
lowerbound=payment
payment=(payment+upperbound)/2
twelvemonth ()
twelvemonth ()