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

Emily emilyyrose at gmail.com
Wed Jun 29 14:18:48 UTC 2011


Looks like it only doesn't copy the spaces for me in Opera (on ubuntu 10.10)
- so I'll make sure to load up firefox from now on when pasting code to the
list :p

for i in range(5,-1,-1) :
    if i == 1 :
        print i, "Bottle of beer on the wall", i, "bottle of beer..."
    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!"
for t in range (5,1,-1) :
    print "Take one down, pass it around!"



On Tue, Jun 28, 2011 at 12:47 PM, Akkana Peck <akkana at shallowsky.com> wrote:

> Good job on lesson 2, everyone! I think I'm making the homework
> assignments a bit too easy. :-)
>
> I liked how people who were more comfortable with programming took it a
> step farther, doing things like distinguishing "1 bottle" from "2 bottles".
> Everybody who did that gets extra credit!
>
> Some people used extra Python features that I haven't covered yet, so
> if you saw stuff in other people's solutions that you don't recognize
> or didn't understand, don't worry: I'll be getting to all of that in
> lessons 3 and 4.
>
> ======== Sending spaces in email =========
>
> I noticed a lot of the posted solutions didn't have any indenting at all.
> In particular, I noticed that from several gmail and yahoo accounts.
>
> I can't figure out what's causing it, though. I have a gmail account,
> so I tried sending myself some Python code from gmail's web interface,
> some using spaces for indentation and some with tabs, and both types
> of indentation came through just fine. So it's not gmail's web
> interface that's making the indentation disappear. Anybody have any
> idea what's going wrong?
>
> Python code is really hard to read if there's no indentation, and it
> won't work at all that way, so since this seems to be a common
> problem, I hope we can figure out what's causing it. I'd be curious
> to hear from the folks whose posts came through with no spaces: did
> you use a webmail interface, or a mail program? Did you copy from
> a text editor or other program then paste into the mail window?
> Did the code use spaces or tabs?
>
> ======== Answers to questions ===============
>
> GcX asked about range(0, 5) versus range(1, 6).  For the purpose of
> printing something five times, they're the same, but most of the time
> you'll care about whether the variable starts at 0, 1, 42 or whatever,
> so it'll be clear where to start your range(). I started with 1 in the
> example because the lesson was getting long and I didn't want to make it
> longer by explaining that programmers usually start counting things at
> zero rather than 1.
>
> Peggy asked three questions. First, about spaces, in particular
> "range(1, 6) :" vs. "range(1, 6):".  They're both fine. Although
> Python cares a lot about indentation (spaces at the beginnings of
> lines), it doesn't care much about spaces after that. With colons,
> parentheses, commas and brackets you can add spaces or not, whatever
> you find easiest to read.  "range ( 1 , 6 ):" and "range(1,6):"
> are equally valid.
>
> Second, is the .py extension necessary? No, and I'll talk more about
> that (and shebangs) in lesson 3.
>
> Third, pydoc. I'm not planning to cover pydoc in this course, though
> I'll probably mention it along with docstrings when I get to functions.
>
> I'll answer Tino's question about else in a separate message.
>
>        ...Akkana
> _______________________________________________
> 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