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

exercise 1.15, I get the problem and what prints out, but what is the sequence of numbers that the guy wants to print or what would the sequence be used for, second part of the exercise?

OpenStudy (anonymous):

I don’t completely understand which sequence you’re talking about, but I did find the Exercise 1.15 a lot more sensible when I did also the optional part of it.

OpenStudy (andrew.m.higgs):

I also struggled to understand what the program was intended to do. I guess this illustrates the importance of commenting code.

OpenStudy (anonymous):

Can you solve it just by using commenting code or do you need to tinker with the code as well?

OpenStudy (andrew.m.higgs):

I don think just commenting will do. Changing the while loop or putting in an if statement to break the while loop is the most likely. Having said that, it its difficult to "fix" the code when we don't really know what the hoped for outcome is.

OpenStudy (anonymous):

I wasn't sure on this? I assumed that because there was a' %2==0' and an' i/2', it was something to do with even numbers. But what about n? I made it so i printed even numbers 10 down to 2. And n printed odd numbers 3 up to 9....Just as an experiment.

OpenStudy (anonymous):

I see two possible solutions for the buggy loop: (v1) counts down 'n' to make 10 iterations, while the second (v2) makes 'i' smaller by 1 each time it’s odd, and therefore reaches 0 and breaks the loop.

OpenStudy (anonymous):

Yes, it runs as an infinite loop the way it is written, and never uses the N = 10 variable. So, you could use the N as a counter to how many times to run the code, or figure out what the code might be trying to do differently. It kind of reminds me of the square root problem discussed in one of the videos.

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!