Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review Fall 2003: What gets printed

(Back to Fall2003 Midterm Review 1)

Answers? Comments? Comments on answers?


Range generates a list up to one less than the upper value you give it, right?

Yes. But what is the definition of a range? What does it mean? It will be much easier for you to understand what this program (and harder ones later) do if you get the range concept. Kelly Farrell



Hello back to you!
Hello
Hello
Hello
Hello
6
Hello back to you!

this is what i think....hello back to you is first because it is the r value, for i in range(1,5), hello is run through the sequence 4 times, so there are 4 hellos, the value is six because value-1=9, then each hello is assigned, 6 is assigned to the fourth hello(1 is subtracted from the value each time through the loop). then r is printed again

lindsay

I like how you walked through your answer step by step.

why isn't print value 5 because 9-4 (for each time it runs through the loop)= 5



No, it's 6 because 10-4 is 6 - value started as 10

If you are having problems understanding this question, try making a chart with two columns: one column for the x value (the number of times you have cycled through the loop) and the corresponding value for your "value" variable. This will help you keep track of what "value" is when you get to the end of the range. Start with 10, go through the loop once, and the value of "value" is 9....you finish from here. Brittany Selden

If you are having trouble with walking this out, use the "Watcher" button in JES: before you run the code, click on "Watcher". Click "Add Var" and then when prompted type "value". Then execute your recipe. The Watcher will trace out every step that it completes and it will tell you the numerical value of "value" at each step. Lauren Biddle

I don't understand what "i" is.


"i" is the individual unit in the list you are going through. For example, in "for i in range(1,5)", "i" is the particular item you are looking at while going through the loop. "i" will start at your first value in the range: 1, and then you'll go through the loop. Then "i" becomes 2 and you go again through the loop. "i" continues to augment by 1 until you reach the last number included in the range. That number, in this case, is 4. Does that make any more sense? Brittany Selden

im assuming we shouldnt use the quotations...is this right?

There are no quotations in the output, that's true. Mark Guzdial




Link to this Page