[Courses] [python] Lesson 2: Loops, if, and beer
sally.hanford1 at ntlworld.com
Fri Jun 24 22:58:40 UTC 2011
Thanks for this enjoyable course, Akkana.
> 1. Your first programming assignment!
> Write a program for the old "bottles of beer" song.
> for i in range(99,0,-1):
> if i ==1:
> print i,"bottle of beer on the wall,",i,"bottle of beer"
> print i,"bottles of beer on the wall,",i,"bottles of beer"
> 2. What does range(0, 10, -1) give? (Try it.)
 I think the largest positive integer must come first in the range if we
are going to decrement. (can the range statement handle negative numbers? -
from my tests I think not.)
> 3. How was the length of this lesson? Too much, too little or just right?
I thought the length was ok. I needed to finish it by midnight (BST) and
started about 11.15pm, but I am switching to another window to finish some
video re-encodes for work, so can't really judge how long it should really
take. I'm also having to refresh my memory about how to use vi as it's ages
since I last used it.
> 4. Write a loop using range() that prints out the first five numbers as
for i in range(1,6):
> Courses mailing list
> Courses at linuxchix.org
More information about the Courses