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

Svenja S. chaosprincess90 at gmx.net
Sat Jun 25 17:12:51 UTC 2011


Hi,

thanks for this course!
I just decided to join in, so I'm late for lesson 1...
Anyway, I'm running python 2.7.2 (and python 3.2, but that shouldn't
matter) on ArchLinux, and I already read the other answers for lesson 1.

On 06/24/2011 10:31 PM, Akkana Peck wrote:
> ===================== Homework =======================
>
> 1. Your first programming assignment!
>    Write a program for the old "bottles of beer" song. It should print
>    something like:
>    99 bottles of beer on the wall
>    98 bottles of beer on the wall
>    97 bottles of beer on the wall
>    ... all the way down to 1.
>
>    Extra credit: make it print the number twice, e.g.
>    99 bottles of beer on the wall, 99 bottles of beer
for i in range(99,0,-1) :
  print i, "bottles of beer on the wall,", i, "bottles of beer"

Mh, looks a bit lazy compared to what everyone else did.
> 2. What does range(0, 10, -1) give?  (Try it.)
>    Any idea why?
[], the empty list? Or array? Not sure.
The range command seems to return anything that is in the range AND can
be reached by adding the step argument.
> 3. How was the length of this lesson? Too much, too little or just right?
Just right.
> Problem 4 is optional -- it's a little harder, but give it a try,
> and if you don't get it, take a look at the answers other students
> post. But try it on your own first, if you can.
>
> 4. Write a loop using range() that prints out the first five numbers
>    as words:
>    one
>    two
>    three
>    four
>    five
for i in range(1,6) :
  if i == 1:
    print "one"
  elif i==2:
    print "two"
  elif i==3:
    print "three"
  elif i==4:
    print "four"
  elif i==5:
    print "five"

This seems a bit too easy, though - and too much work for a lazy person
like me.
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
>



More information about the Courses mailing list