Ask your own question, for FREE!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW) 13 Online
OpenStudy (anonymous):

Hi, in section 1.15 "the buggy loop" Written Exercises 1 of 6.189 A Gentle Introduction to Computer Science, can anybody help me to figure out what the program really is intended do ? note that i have no problem to debug it

OpenStudy (e.mccormick):

That is part of the problem. Trying to tell what it could be meant to do. Without comments, it is very hard to know. So there is no way to properly fix it because goal is unstated.

OpenStudy (anonymous):

Are there buggy parts that are recognizable even without knowing what the code is meant to do? For example, isn't n = 10 extraneous???

OpenStudy (e.mccormick):

Not necessarily extraneous. What if the code that used n=10 was accidentally left out and that is the real bug? ``` n = 10 i = 10 while i > 0: print i if i % 2 == 0: i=i/ 2 else: i=i+1 ``` Now that will do: 10 5 6 3 4 2 1 2 1 repeat forever... But what if the relationship to n was supposed to be different? Like n being the one modified an i just being decremented? There are dozens of possibilities. As it points out in "There’s a lot of mistakes in the code so your guess is as good as ours!" they are all just guesses. No way to know what was really meant.

OpenStudy (bkglass):

My approach was to just have it stop looping and print at the end the point of the exercise. n = 10 i = 10 while i > 0: print i if i % 2 == 0: i = i / 2 else: i = i - 1 if i == 0: print 'I dont know what this guy is doing'

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!