[Courses] [python] Lesson 2: Loops, if, and beer
Marcela Musgrove
mmusgrove at gmail.com
Sun Jul 3 18:11:39 UTC 2011
Didn't respond last week but I'm running: Python 2.6.1 on Mac
On Fri, Jun 24, 2011 at 1:31 PM, Akkana Peck <akkana at shallowsky.com> 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,-1,-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?
[ ]
can't count backwards from 0 to 10
this is also what i got when I typed range(10,2) in lesson though
> 3. How was the length of this lesson? Too much, too little or just right?
Seemed ok length, still catching up this week
>
> 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"
else:
print "five"
More information about the Courses
mailing list