2009/2/6 michel paul <mpaul...@gmail.com>: > Warren, > > Your book looks great! I'd be interested in seeing the rest of it. Yeah, > we ended up discussing how to represent a deck of cards in class as well. > One of the kids got inspired while creating the dice simulation and emailed > me asking how to do something like that. So I was really glad to see this > start growing organically. We haven't discussed classes previously, as that > would REALLY have scared them off, so I just had him continue at the level > of simple lists, thinking of cards as simple ordered pairs: > >>>> suits = ['S', 'H', 'D', 'C'] >>>> ranks = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K'] >>>> deck = [(rank, suit) for suit in suits for rank in ranks] >>>> shuffle(deck) >>>> hand = [deck.pop() for card in range(5)] >
Good stuff. I'm always tempted to have 'S','H','D','C' replaced by the actual symbols (DejaVu font?), keeping the quote marks as these symbols don't qualify as identifiers, only strings. Here's the relevant page from the Unicode charts. http://unicode.org/charts/PDF/U2600.pdf Let's see what I can do with Python here... >>> import unicodedata >>> heart = chr(0x2665) >>> unicodedata.name(heart) 'BLACK HEART SUIT' I thought hearts were red... I've uploaded a screen shot using these characters in IDLE/Py3K: http://www.flickr.com/photos/17157...@n00/3259871142/ Also, I've finally gotten around to getting my I Ching stuff ported to a Google appengine: http://osgarden.appspot.com Lots of Chinese characters, though not top-level (this is Python 2.5 anyway -- see About page for source). Yes, I use Justin's PyFontify with py2html, colorize code on the fly (had to modify py2html a little). > He played around with this and really got into it. Good news! It's amazing > how much you can do in a simple interactive way with Python. I mean, this > LOOKS like what you do with a deck! But I did try to sow some seeds by > mentioning how you could accomplish even more by thinking in terms of > functions and classes. > > - Michel Yes, REPL is what kids like, though they don't call it REPL (read, evaluate, print loop -- what the interpreter does). I might try EDSL for "eat, digest, say loop" -- you could think of others. In the 1980s the paradigm with BASIC etc. was "write a little program and prompt yourself for inputs" (ala raw_input), but it's easier at first to just work in a session, more like in Logo and APL, cluttering up the workspace (i.e. __main__) with all kinds of remembered stuff. Play around, then cut and paste we you want to keep for next time, some exceptions and debugging already happening interactively. We don't start by writing then running programs, we start by talking to the interpreter, importing existing libraries, poking around. When we we start saving stuff, we think of our first files more like the math library, or string, i.e. a box of tools that we use directly. The math module has no raw_input prompts -- that'd be silly. So our first saved .py files aren't "programs", they're "modules". They may have unit tests or doc tests, should at least have documentation of some kind, but there's no need for a main() or any unifying structure. It's not a "script", it's a "bag of useful things" (a namespace). Some functions, some classes, even some constants maybe... KIrby _______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig