[Edu-sig] My experience teaching Python

Martijn Faassen faassen@vet.uu.nl
Wed, 23 Feb 2000 12:27:37 +0100

Dustin James Mitchell wrote:
> On Tue, 22 Feb 2000, Martijn Faassen wrote:

[from sum to product]
> > Also tricky was
> > to change the starting value of '0' to '1' (otherwise the result is '0'), but
> > they both could figure this out for themselves.
> And that's a math issue, not a programming issue.

I think it's also a programming issue. In math, you just *do* the product,
while in my loop example, the product was done in multiple steps:


# sum

# the simple math way
sum = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9

# the programming way
sum = 0
for i in range(1, 10):
    sum = sum + i

# product

# the simple math way
product = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9

# the programming way
product = 1
for i in range(1, 10):
    product = product * i

As you can see, doing it the math way doesn't even raise the 0 versus 
1 issue in this case, but doing it programmatically does.

> It's always nice to
> cross people over that gap, because math like that (0 times anything is 0)
> is something everyone is familiar with, and thus grounds the learning in
> something familiar.

That's true, of course. You can appeal to lots of the basic math skills of
people. My friend was amused by the idea that Python knew how to do
complicated additions already, while she has to spend lots of time 
teaching the same to her daughters. :)

> > That's about as far as I got this time. As you see you can spend lots of
> > time with the basics. This is not because the mechanisms of the basics
> > are generally hard to understand; they picked those up pretty well in 
> > general, though there were some problems. The problem is more one of
> > *why* these mechanisms are useful. What you can do with them, and how
> > you use them to do useful things. That's the real art of programming
> > (along with the importance of a well readable and maintainable program
> > structure).
> You picked a good set of basics to start with.  For some people, however,
> who are 'innumerate', Python's string facilities can be useful -- use
> looping over sequences to do various manipulations of words and
> sentences...

Though I am rather dubious if it's worth or doable teaching programming to
people innumaterate to the extent that they don't know basic addition and
multiplication. Of course string and word manipulation is very interesting
too, and I did some basic string concatenation (to demonstrate different
types and the power of expression). I hadn't gotten to the more complicated
function calling though (i.e. string.split()). I still have to explain
'import' at this point! :)