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

Emily emilyyrose at gmail.com
Sat Jun 25 03:19:41 UTC 2011


1)

for i in range(5,-1,-1) :
if i == 1 :
print i, "Bottle of beer on the wall,", i, "bottle of beer..."
print "Take one down, pass it around!"
elif i == 0 :
print "No more bottles of beer on the wall, no more bottles of beer..."
else :
print i, "Bottles of beer on the wall,", i, "bottles of beer!"
print "Take one down, pass it around!"

:D

2) plain brackets, because 0 minus 1 is -1 which is less than 0... and thus
not in the range :p)

3) perfect - hard enough to make me think and play around with it, but not
so long to get fustrated. Thanks! LOTS of fun! :)

4) There's probably an easier way to do this... but:
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"

On Fri, Jun 24, 2011 at 9:04 PM, Leslie <leslie.brothers at verizon.net> wrote:

> Two questions from this lesson:
> >
> > At the Python >>> prompt, try typing:
> > range(10, 2)
> > [2, 4, 6, 8]
> I didn't get that. I got:
> >>> range(10, 2)
> []
> >>>
> What gives?? I did not get [2, 4, 6, 8]
> However, if I typed
> range (10, 2, -2), I got [10, 8, 6, 4]
>
> >
> > for i in range(1, 6) :
> >     if i == 3 :
> >         print "i is three!"
> >     elif i == 4 :
> >         print "now it's four!"
> >     else :
> >         print "Hello, world! i =", i
>
> This question is about interactive (console) Python.
> I entered the above but had a typo in the first line so I got an error
> message.  Is there a way to correct a line retroactively when you are in
> interactive Python (>>>) mode -- so you don't have to just enter the
> whole thing all over again?
>
> Thanks,
>
> Leslie
> >
>
>
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
>



-- 
Whatever you can do, or dream you can, begin it. Boldness has genius, power
and magic in it. -  Goethe

Be who you are and say what you feel because those who mind don't matter and
those who matter don't mind. - Dr.Seuss

Not everything that can be counted counts, and not everything that counts
can be counted. - Albert Einstein


More information about the Courses mailing list