Python Forum
Another infinite loop
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another infinite loop
#3
I edited my code to
annualInterestRate=.1
balance=100
monthlyInterestrate=annualInterestRate/12
balance_initial=balance
lowerbound=(1/12)*balance
upperbound=balance*(1+monthlyInterestrate)**(12)/12
monthlyPayment=(upperbound+lowerbound)/2
while balance>-.00001 and balance<.00001:
    for i in range(12):
        balance=balance-monthlyPayment + (balance-monthlyPayment)*monthlyInterestrate
    if balance>0:
            monthlyPayment=(upperbound+monthlyPayment)/2
    if balance<0:
            monthlyPayment=(lowerbound+monthlyPayment)/2
    
print('Lowest Payment: ' + str(round(monthlyPayment, 2)))
but now everything is off by a small amount.
For instance, a balance of 320000 and an annualInterestRate of .2 should yield "Lowest Payment: 29157.09" but I'm getting 29591.88

I'm quite confused as to why this still isn't working.
Reply


Messages In This Thread
Another infinite loop - by wlsa - Jul-19-2018, 12:41 AM
RE: Another infinite loop - by ichabod801 - Jul-19-2018, 01:37 AM
RE: Another infinite loop - by wlsa - Jul-19-2018, 02:03 AM
RE: Another infinite loop - by buran - Jul-19-2018, 03:31 AM
RE: Another infinite loop - by ichabod801 - Jul-19-2018, 06:21 AM
RE: Another infinite loop - by buran - Jul-19-2018, 06:41 AM
RE: Another infinite loop - by ichabod801 - Jul-19-2018, 06:43 AM
RE: Another infinite loop - by wlsa - Jul-20-2018, 12:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Infinite loop Danado 4 2,392 Aug-16-2021, 05:56 PM
Last Post: deanhystad
  Help with while loop creating an infinite loop. FWendeburg 3 3,075 Jan-30-2019, 08:28 PM
Last Post: FWendeburg
  Infinite loop/ only half working anclark686 5 4,802 Sep-09-2018, 07:31 AM
Last Post: buran
  Why is this giving me an infinite loop? wlsa 4 3,960 Jul-25-2018, 10:11 PM
Last Post: cyberpatje
  How to stop an infinite loop in spyder if it's currently running? wlsa 3 24,764 Jun-30-2018, 03:27 AM
Last Post: ichabod801
  Infinite loop Truman 9 9,168 Jan-19-2018, 11:25 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020