python - how can i get newBalance to == outstandingBalance when loop iterates through range and newBalance > 0 -


outstandingbalance = 1800   #declaring variables apr = .18   interest = apr / 12         #annual interest rate minpay = 0                #minpayment needed payoff balance in year newbalance = outstandingbalance  month = 0 #month counter  while newbalance>0:     month = month+1                  minpay = minpay + 10     in range(1, 13):         newbalance = newbalance * (1+interest) - minpay          if newbalance < 0:             break 

so trying newbalance go outstandingbalance value when loop iterates through range , newbalance still >0 can increase minpay each iteration 10 until @ 12 months newbalance <0

as understand it, you're trying determine minimum monthly payment needed ensure outstanding balance paid off within year, , you're approaching incrementing minimum payment 10 until balance paid within year. can code , running moving newbalance = outstandingbalance line loop ensure you're restarting calculation original balance each time:

outstandingbalance = 1800 apr = 0.18 interest = 0.18 / 12 minpay = 0  while true:     newbalance = outstandingbalance     minpay += 10     in range(12):         newbalance = newbalance * (1.0 + interest) - minpay     if newbalance <= 0:         break  print "minpay needed:", minpay # minpay needed: 170 

to exact minimum payment needed pay off loan in 12 months, use zero-finding algorithm newton's method:

import scipy.optimize  outstandingbalance = 1800 apr = 0.18 interest = 0.18 / 12 minpay = 0  def balanceafteryear(x, outstandingbalance, interest):     newbalance = outstandingbalance     in range(12):         newbalance = newbalance * (1.0 + interest) - x     return newbalance  print scipy.optimize.newton(balanceafteryear, 0.0, args=(outstandingbalance, interest)) # 165.023987231 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -