[Courses] [python] Lesson 2: Loops, if, and beer

Hanford Sally 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"
>   else:
>     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
> words:

for i in range(1,6):
  if i==5:
    print "five"
  elif i==4:
    print "four"
  elif i==3:
    print "three"
  elif i==2:
    print "two"
    print "one"

>   _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses

More information about the Courses mailing list