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 PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Fall 2006 Midterm 1 Review: Tracing the printing

Questions?


I

you
you
you
you
walrus
4

Why is it a 4? Earlier we set value = 0, then later we set value = value +1, so that would be 0+1 = 1, right? I understand the for loop loops 4 times, but how does that change the value?
Ok. So Value starts out at 0. What happens to the value of value after each time through the for loop? -Albert d'Heurle

what in the world does x mean in for x in list1
Its just a more fancy way of writing a 'for' loop.
list1 = range(1,5)
The above line means that
list1 = [1, 2, 3, 4]
Now the 'for' loop just goes through every value in the list. In short, its the same thing as writing
for x in range(1,5):
- Bobby Mathew


why isn't list 1= [1,2,3,4,5]?
That's just the way that range is defined. It goes from the first value up to but not including the second value, so range(1,5) excludes 5 from the list. There is an obscure justification that makes this useful in some situations, but mostly it's a pain that causes programming errors until you get used to it. Every programming language contains gotchas like this. Python has fewer than most. Colin Potts



Link to this Page