class Dog:
def __init__(self, name):
self.name = name
and using it to create instances dog1, dog2 (Fido and Rover). Then I went back and added a bark method. The point was to introduce the class/instance distinction. I use this wrap about a house blueprint, and an architect using it to build an instance in Beaverton and Mt. Tabor (local neighborhoods): one blueprint, two actual houses (or house objects). Then I go back to my dogs.
All this is a prelude to reinforcing "dot notation" i.e. now that we have dog.name and dog.bark(1), it makes more sense to discuss a first collection type: lists. We gradually build up the following function, in several iterations, with kids entering at their workstations, watching my projected version up front:
def askme(howmany=3):
dogs = []
for i in range(howmany):
thedog = raw_input("Dog's name? ")
dogs.append(thedog)
dogs.sort()
return dogs
I was thinking of Arthur's suggesting to reinforce the distinction between 'print' and 'return'. A first draft of the above function simply prints, doesn't sort. Then I talk about returning a value versus echoing it to screen (essentially what 'print' does -- not to a printer (one girl asked me about that)). Also, we start without any argument, looping 3 times. Adding howmany is a separate step, making it default to 3 yet another iteration.
I like the way IDLE lets me "copy down" i.e. continually re-edit a given function, gradually adding to it. I'm projecting in 20 pt type or so, using Comic Sans (looks friendly).
This is all very basic stuff, not breaking much new ground. I'm experimenting with how to introduce "dot notation" which I regard as very important. Really, it should be incorporated into standard math notations in a more integral way. object.verb(args) and object.property just makes a lot of sense as a standard way to notate.
"""
In my view, the mathematicians have been too slow to acknowledge dotAnother recent mention of Python in education (today, by me):
notation as a legitimate contribution to mathematics proper. The math books
don't allow that A.b(z) is a good way to organize thinking, A being an
object of some type, perhaps inheriting from parent types, and b being a
method, accepting argument(s) z. v1.add(v2) is as smart a way to signify
vector addition as v1 + v2, plus makes it clear where the methods belong:
in the class definitions.
When math students are asked to actually number crunch with these
mathematical objects (quaternions say), dot notation is what they encounter,
more often than not. And yet there's this artificial line that gets drawn:
"that's just the computer's way of expressing things, not really a math
notation" is the party line (I'm not in that party).
"""
Source: http://mail.geneseo.edu/pipermail/math-thinking-l/2006-February/000982.html
http://mathforum.org/kb/thread.jspa?threadID=1337652&tstart=0
Kirby
_______________________________________________ Edu-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/edu-sig
