[Courses] [python] Lesson 2: Loops, if, and beer
Maria Inmaculada de la Torre
idelatorreie at gmail.com
Mon Jun 27 16:30:09 UTC 2011
---------- Forwarded message ----------
> From: Akkana Peck <akkana at shallowsky.com>
> To: courses at linuxchix.org
> Date: Fri, 24 Jun 2011 13:31:11 -0700
> Subject: [Courses] [python] Lesson 2: Loops, if, and beer
>
> ===================== 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
>
This is what I did:
*for i in range(99, 0, -1) :*
* print i, "bottles of beer on the wall,", i, "bottles of beer"*
>
> 2. What does range(0, 10, -1) give? (Try it.)
> Any idea why?
>
*It returns an empty set of brackets [] so I guess it can't do anything
because it's mathematically impossible. *
>
> 3. How was the length of this lesson? Too much, too little or just right?
>
*The lesson for me was fine, thanks so much for taking the time of doing
this. :) *
>
> 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
>
I couldn't do it so I'm checking everyone else's answers *redface*
Thanks so much for the lessons, and waiting for the next one. :)
More information about the Courses
mailing list