Python Forum
Another infinite loop
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another infinite loop
#1
The given problem: use bisectional search to find the minimum monthly payment to pay off debt after 12 payments (slight.
Assume that the interest is compounded monthly according to the balance at the end of the month (after the payment for that month is made).

annualInterestRate=.1 # i used these numbers soley as placeholders to test the program
balance=100 # i used these numbers soley as placeholders to test the program
monthlyInterestrate=annualInterestRate/12
balance_initial=balance
lowerbound=(1/12)*balance # the upperbound and lowerbound were defined in the given problem for us.
upperbound=balance*(1+monthlyInterestrate)**(12)/12 
monthlyPayment=(upperbound+lowerbound)/2
while balance!=0:
    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
    balance=balance_initial
print('Lowest Payment: ' + str(round(monthlyPayment, 2)))
Is there something wrong with my bisectional search? I've been looking at it for some time and I don't see how this could give me an infinite look; if the monthlyPyament is too large it is lowered, and if it is too small it is raised until the minimum balance is found.
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,373 Aug-16-2021, 05:56 PM
Last Post: deanhystad
  Help with while loop creating an infinite loop. FWendeburg 3 3,044 Jan-30-2019, 08:28 PM
Last Post: FWendeburg
  Infinite loop/ only half working anclark686 5 4,766 Sep-09-2018, 07:31 AM
Last Post: buran
  Why is this giving me an infinite loop? wlsa 4 3,922 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,735 Jun-30-2018, 03:27 AM
Last Post: ichabod801
  Infinite loop Truman 9 9,136 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