[Tutor] infinite while loop
marcus.luetolf at bluewin.ch
marcus.luetolf at bluewin.ch
Fri Oct 1 14:23:24 EDT 2021
Hello Experts,
I'm stuck with not beeig able to stop the while loop in the script below
which should
yield the minimumFixedMonthlyPayment (in steps of 10) to payoff a balance
in 12 months
according to the variables set.
The script below creates an indefinite loop and I don't understand why the
the loop
does not stop when the variable "previousBalance > yields negative values
despite
the condition set for the while loop.
Where is my mistake ?
>balance = 1000
>previousBalance = balance
>minimumFixedMonthlyPayment = 10
>annualInterestRate = 0.2
>monthlyInterestRate = (annualInterestRate) / 12.0
>while previousBalance > 0.0:
>for i in range(12):
>monthlyPaidBalance = (previousBalance) -
(minimumFixedMonthlyPayment)
>updatedBalanceEachMonth = (monthlyPaidBalance) +
(monthlyInterestRate * monthlyPaidBalance)
>previousBalance = updatedBalanceEachMonth
>print('previousBalance:', round(previousBalance,2))
>print('minimumFixedMonthlyPayment:',
minimumFixedMonthlyPayment)
>previousBalance = balance
>minimumFixedMonthlyPayment += 10
>print(previousBalance, minimumFixedMonthlyPayment)
More information about the Tutor
mailing list