Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

Anyone know why I am getting an endless loop ?

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at in under 10 minutes. Go to now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly


Get your free account and access expert answers to this and thousands of other questions

because first while loop is continuestly exicuting:- while(balance > 0): balance = 4213 mmp += 10 it will never come out. balance value will never get down to 0.
That's not correct. It has nothing to do with the outer loop. It has to do with the fact that on the second iteration of the outer loop, the "m" variable is not reset. Therefore the second while loop is not executed! What he is doing, by resetting the balance is totally correct!
What @Chris2332 says is very right! -You have your inner while loop to repeat the months round. -OK -You have the iteration control variable ,set and changing.-OK -What you dont have, is that same variable reseting in your outter loop so that you can run it again on your next try to find the mmp. Means that ,on your next try ,where you have mmp raising you will have m=13 from your last iteration round and that will not enter inner while loop. Hope that helps!:)

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

I reset it but still no joy
Why at the end of your inner loop are you resetting the mmp?
No need to reset mmp. both the while loops are depend on blance and m values.
Of course, it is a throwback to the original from 1st problem when it was the minimum payment, but not needed on this
Guys... I've said it a million times... solve the problem on paper and then move on to programming. If you don't understand the solution to the problem, how do you expect to write the code to solve it?
An other thing, not error generating ,but important : line 7 : u have inizialized m=1. OK but since you are doing this in the while loop ,there it is no more needed. HElps you keep your code cleaner and more readable.
If you would like to run it once then try this code:- balance = 4213 annualInterestRate = 0.2 monthlyPaymentRate = 0.04 monthlyInterestRate = annualInterestRate/12 mmp = 10 paid = 0 m = 1 if (balance !=0): balance = 4213 mmp += 10 while(m <=12): m += 1 balance = (balance - mmp)*(1 + monthlyInterestRate) paid = mmp + paid mmp = monthlyPaymentRate*balance print 'Total paid: ',round(paid,2) print 'Remaining balance: ',round(balance,2)
It is helpful??
Yes that seems to work , Thanks
I am only a beginner so do not have much real world experience at thinking up methods
@rambo2210 mate seriously do you know you are not supposed to give out the answer before the PS is due?-.-
It is very ok.:-) feel free to ask you question here. BTW, I dont know phython. but I have programming skill so I could solve you problem.
Doesn't pass grader but I will keep trying
@MicroBot what ?? I did not get you.
Doesn't pass grader though seems to work fine
you gave him the whole code and thats is not allowed ...he is supposed to resolve it is ok as we all need help to understand things but like this ..... From: "It is not ok to post answers to lecture and problem set problems before the submission deadline."
@minimallinux keep trying mate!im sure you can do it you just need a clean head .What i do is when i resolve a step i had problem with...i take a smthing different....dunno go make a tea or a coffe and the return to next problem i have!:) helps a lot
Seems others more experienced have problems with this one too
@MicroBot Oops. I m really very sorry for this. I did not know this. Please forgive me.
Not for me to forgive you:) Just ppl have to keep in mind what is fair and what it not!:)
@minimallinux well i know whatis the problem but u have to promise me that you will spend time to understand the version that rambo gave you before sending it!
@MicroBot from where I will find all this problems I also want to solve.
balance = 4213 annualInterestRate = 0.2 those 2 you mustnt initialize them as the EdX tester has its own way to give values to your variables. just delete it and send without it!
@rambo2210 check EdX page MITx: 6.00x Introduction to Computer Science and Programming you have still time to start it and do in time the PS1 that is due on monday. GL
I already removed them before submitting, so I don't know why it fails, but anyway I have to try to go over it myself, just submitting something already done serves no purpose.
In fairness, the inner loop is my own code anyway, its just the outer loop, I probably wouldn't have got that at present
Good keep it up.. you will get you answer soon.
Well mini if you believe that ,for loop is better or more understanding ,you sure can and should use it...its enough that you understand what you are writing. Thats all!
It is not right anyway, the program asks for the lowest payment which clears the balance, and the notes recommend using a while loop, I was probably on the right track previously
Solve it on paper first!
This course is hard !
Come on mate... it's the first couple of's not hard. You just want to find a quick solution without understanding everything. Be focused and you ll be ok!
Yes, you are right, quick solution is no good
What @Chris2332 means, is that when you do it on paper ,1st you have infinite possibilities to edit and build and design and think over your code!When you write directly into the editor you are ,subconciously ,scared to make a mistake cause you would have a hard time retyping other things and this does not unfold your mind does not let you concentrate on the problem but on the use of python.....
I find it hard to work out on paper as I have not presently sufficient knowledge t o ascertain what everything is going to do, but I will work on it. I have done a new version which comes up with the correct end result but does some strange things in the meantime like increasing the balance alarmingly before somehow correcting it Its here
Doesn't pass the checker
1st of all: (i know its only initialized not used anywhere but why u keep the monthlypayment rate in ur code anyway?
Thats left over from previous section needs to remove Thanks
Cant see why the balance goes up, print is there to check that, its not needed for checker
plus....remove all extra print outs....u have to have the output they ask u to have. ill check now about balance.
still you have not got the output? may I help u.?
can you just post the question here so that I can give some help.
Just done a new version which gives correct result but doesn't pass checker and does some strange things with the balance before seemingly fixing them
while(balance > 0): balance = 3926 this gives u the problem too as when u send it for checking no matter what they put to be balance ...u always set it to 3926....assign balance value to smthing else.
No in checker that is removed and not set as per usual
OK I see that I should set balance = balance in loop instead of 3926
how about smthing like this?: target_balance=balance
the fact that at start ur rem balance raises is that the 1st payment tests are too low and with the monthly interest rate added it goes up. so its normal.
guys I have the sollution. but dont know how to show you that as @MicroBot told me not to post code here.
OK got that
Just give a hint
AT what area I should be looking at
ok. so you are talking about why are you getting -30.5 rgt?
No we were talking about raised balances but that is normal, I took out the print statements and now I am getting the wrong outcome !! (should be 360)
nop the problem says that it is normal to get a negative number as u r raising the payment by staps of 10.and i assure u it is legal for the checker aswell. what he asks is that ata start the remaining balance starts to become bigger instead of becoming lower .And that is normal too if u manually try to calculate the rem balance at low payment numbers.
because u set balance=balance
So I can set it to ?
I must be close to this now
u can say i wrote u above x=balance and use that as a new variable. or smthing = balance:)
u can set it to as i wrote above*
ok so here is the hint. the problem is with 2nd loop. 2nd loop will run for 12 times rgt? and you are checking the condition after that loop. try using condition in side 2nd loop..
Hope that rings a bell for you.
w8 sec stop everything u are doing xD
@MicroBot you know the solution rgt?
you know that where he is doing the mistake?
I am getting the final print as follow:- Remaining balance: 330 Lowest Payment: 360 Is it correct??
mini stop doing this exercise for 5-10 mins...go do smthing else that has nothing to do with programming....cause now while we give u a mill of hints and suggestions u r trying to figure it out with our heads not with urs...clean ur head and ull understand im sure..then return to it and see it with new eyes!please do so!
Yes will do its become confusing I was very close to this one
@rambo yes i do know the solution but he needs a break!
yeap you are right. @MicroBot
@MicroBot I am getting the final print as follow:- Remaining balance: 330 Lowest Payment: 360 Is it correct??
I get 360 if i set balance = 3926 in inner loop
@rambo2210 based on his program im getting lowest payment 360 and rem balance -30.5...negative rem balance is fine for the solution.
having a rest for a bit this is what I've got
but doesnt pass checker because of value 3926 in inner loop I beliave
it is right but u have to adjust ur code to be readable by their checking program. ur program as it is now works only for balance =3926 unles u manualy change it from inside. (think of it as a user not a developer)
mini go rest !xD
So got you solution?

Not the answer you are looking for?

Search for more explanations.

Ask your own question