[Tutor] infinite while loop
Marcus Lütolf
marcus.luetolf at bluewin.ch
Sat Oct 2 05:13:53 EDT 2021
Thank you.
The previousBalance is set back to 1000 after each run oft he for loop intentionally for the
following for loops should run with minimumFixedMonthlyPayment each time increased by 10
til previousBalance get's negative.
The while loop should then stop, when previousBalance gets smaller than 0 but it doesn't.
Might it be a problem of scope ?
-----Ursprüngliche Nachricht-----
Von: Susana <lists at linguarum.net>
Gesendet: Freitag, 1. Oktober 2021 20:47
An: marcus.luetolf at bluewin.ch
Cc: tutor at python.org
Betreff: Re: [Tutor] infinite while loop
Hi,
"previousBalance" reaches while condition (< 0.0) inside the for loop, but then it is set to the value of "balance" in the line:
previousBalance = balance
So I think that "previousBalance" is always 1000 when the while condition is checked.
Hope this helps.
Cheers,
--
Susana Sotelo Docío gpg-id: 0E9BEDA4
marcus.luetolf at bluewin.ch escreveu:
> 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)
>
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https:
More information about the Tutor
mailing list