Reputation: 193
The second loop doesnt work. When I compile it doesnt output any text, it just asks for the inputs and stops there
It means that the second loop isnt being executed, just the first one but i dont know why
balance0 = float(input("balance = " ))
annualInterestRate = float(input("annualInterestRate = " ))
monthlyPayment = 10
balance = 0
month = 1
while (0):
balance = balance0
while month <= 12:
balance1= (balance + annualInterestRate * balance/12)
balance1 = balance1 - (monthlyPayment)
print("Remaining balance month " , month, " is ", balance1)
balance = balance1
month += 1
if balance < 0:
print("Lowest payment: ", monthlyPayment)
break
else:
monthlyPayment += 10
The loop
while month <= 12
doesnt make it to run, why?
Upvotes: 0
Views: 137
Reputation: 77847
Everyone else already caught teh main problem. You also neglected to reset your month counter. The result is that if $10/month doesn't pay off the loan, you go into an infinite loop. Try this:
while (True):
balance = balance0
for month in range(1, 12+1):
When you know how many times you need to iterate, use a for statement.
Also, you might use a better customer prompt: annualInterestRate is a variable anem, and hard for a mundane human to read. Change this to "Annual interest rate; e.g. 0.12 would mean 12% interest".
Upvotes: 0
Reputation: 40335
It's actually your outer loop that doesn't run. You have:
while (0):
Since (0)
is never a true condition, that loop will never execute. Based on the fact that you've got a break
in there later on to terminate it when some condition is met, you probably mean:
while (1):
As an aside, while True:
is generally equivalent, and probably more idiomatic.
Upvotes: 2