Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
Anyone know why I am getting an endless loop ?
http://codepad.org/Q9UuBR1l
 one year ago
 one year ago
Anyone know why I am getting an endless loop ? http://codepad.org/Q9UuBR1l
 one year ago
 one year ago

This Question is Closed

rambo2210Best ResponseYou've already chosen the best response.1
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.
 one year ago

Chris2332Best ResponseYou've already chosen the best response.1
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!
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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!:)
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
I reset it but still no joy http://codepad.org/pZwfvY9j
 one year ago

Chris2332Best ResponseYou've already chosen the best response.1
Why at the end of your inner loop are you resetting the mmp?
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
No need to reset mmp. both the while loops are depend on blance and m values.
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Of course, it is a throwback to the original from 1st problem when it was the minimum payment, but not needed on this
 one year ago

Chris2332Best ResponseYou've already chosen the best response.1
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?
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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.
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
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)
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Yes that seems to work , Thanks
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
I am only a beginner so do not have much real world experience at thinking up methods
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
@rambo2210 mate seriously do you know you are not supposed to give out the answer before the PS is due?.
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
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.
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Doesn't pass grader but I will keep trying
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
@MicroBot what ?? I did not get you.
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Doesn't pass grader though seems to work fine
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
you gave him the whole code and thats is not allowed ...he is supposed to resolve it alone....help is ok as we all need help to understand things but like this ..... From: https://www.edx.org/static/contentmit600x~2012_Fall/handouts/Collaboration_guidelines.7c42c319b037.pdf "It is not ok to post answers to lecture and problem set problems before the submission deadline."
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
@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 break...do smthing different....dunno go make a tea or a coffe and the return to next problem i have!:) helps a lot
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Seems others more experienced have problems with this one too
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
@MicroBot Oops. I m really very sorry for this. I did not know this. Please forgive me.
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
Not for me to forgive you:) Just ppl have to keep in mind what is fair and what it not!:)
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
@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!
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
@MicroBot from where I will find all this problems I also want to solve.
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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!
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
@rambo2210 check EdX page https://www.edx.org/dashboard 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
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
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.
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
In fairness, the inner loop is my own code anyway, its just the outer loop, I probably wouldn't have got that at present
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
Good keep it up.. you will get you answer soon.
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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!
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
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
 one year ago

Chris2332Best ResponseYou've already chosen the best response.1
Solve it on paper first!
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
This course is hard !
 one year ago

Chris2332Best ResponseYou've already chosen the best response.1
Come on mate... it's the first couple of lectures...it's not hard. You just want to find a quick solution without understanding everything. Be focused and you ll be ok!
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Yes, you are right, quick solution is no good
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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 ...it does not let you concentrate on the problem but on the use of python.....
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
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 http://codepad.org/2gw0bTcD
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Doesn't pass the checker
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
1st of all: (i know its only initialized not used anywhere but why u keep the monthlypayment rate in ur code anyway?
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Thats left over from previous section needs to remove Thanks
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Cant see why the balance goes up, print is there to check that, its not needed for checker
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
plus....remove all extra print outs....u have to have the output they ask u to have. ill check now about balance.
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
still you have not got the output? may I help u.?
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
can you just post the question here so that I can give some help.
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
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 http://codepad.org/spD9OZ1u
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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.
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
No in checker that is removed and not set as per usual
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
OK I see that I should set balance = balance in loop instead of 3926
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
how about smthing like this?: target_balance=balance
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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.
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
guys I have the sollution. but dont know how to show you that as @MicroBot told me not to post code here.
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
AT what area I should be looking at
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
ok. so you are talking about why are you getting 30.5 rgt?
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
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 !! http://codepad.org/WezAh8ef (should be 360)
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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.
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
because u set balance=balance
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
So I can set it to ?
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
I must be close to this now
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
u can say i wrote u above x=balance and use that as a new variable. or smthing = balance:)
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
u can set it to as i wrote above*
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
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..
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
Hope that rings a bell for you.
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
w8 sec stop everything u are doing xD
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
@MicroBot you know the solution rgt?
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
you know that where he is doing the mistake?
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
I am getting the final print as follow: Remaining balance: 330 Lowest Payment: 360 Is it correct??
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
mini stop doing this exercise for 510 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!
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
Yes will do its become confusing I was very close to this one
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
@rambo yes i do know the solution but he needs a break!
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
yeap you are right. @MicroBot
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
@MicroBot I am getting the final print as follow: Remaining balance: 330 Lowest Payment: 360 Is it correct??
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
I get 360 if i set balance = 3926 in inner loop
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
@rambo2210 based on his program im getting lowest payment 360 and rem balance 30.5...negative rem balance is fine for the solution.
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
having a rest for a bit this is what I've got http://codepad.org/FNCkLfJy
 one year ago

minimallinuxBest ResponseYou've already chosen the best response.0
but doesnt pass checker because of value 3926 in inner loop I beliave
 one year ago

MicroBotBest ResponseYou've already chosen the best response.0
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)
 one year ago

rambo2210Best ResponseYou've already chosen the best response.1
So got you solution?
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.