[Courses] [python] Lesson 2: Loops, if, and beer
Tino van Uffelen
tufforama at yahoo.com
Wed Jun 29 12:06:57 UTC 2011
On the subject of spaces, I only noticed this went wrong after you pointed this out to me, I copy/pasted the code from geany to yahoo mail (web). I haven't got a clue why there are no spaces after pasting, they sure were there when I copied them. Guess I'll just have to check what I've copied.
Regards
Tino
________________________________
From: Akkana Peck <akkana at shallowsky.com>
To: courses at linuxchix.org
Sent: Tuesday, June 28, 2011 6:47 PM
Subject: Re: [Courses] [python] Lesson 2: Loops, if, and beer
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
More information about the Courses
mailing list