
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)]
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 On Fri, Feb 6, 2009 at 9:21 AM, Warren Sande <warren.sande@rogers.com>wrote:
Michel,
Sounds like you caught their interest, which is great. I have a chapter on probability and simulation in my book, "Hello World! Computer Programming for Kids and Other Beginners". It talks about simulating dice, coins, and a deck of cards. In the second half of the chapter we make a Crazy Eights card game (text-based). I've attached a preview of the chapter if you want to have a look. Keep in mind that this is one of the later chapters, and we have already covered the basics like loops, lists, objects, etc.
By the way, the book has had some delays in production, but it should be out in the next few weeks.
Regards, Warren Sande
------------------------------ *From:* michel paul <mpaul213@gmail.com> *To:* "edu-sig@python.org" <edu-sig@python.org> *Sent:* Thursday, February 5, 2009 1:34:49 PM *Subject:* [Edu-sig] probability & simulation
We began a unit in math called 'Probability and Simulation'. The students of course have to solve many typical problems involving dice and coins. This provided a perfect opportunity for incorporating Python in a way that didn't freak the kids out. Remember, I have been trying to weave Python into a math environment where programming is seen as something alien and scary. Bizarre. The 'choice' function in the random library provides an excellent way to create all kinds of simulations very easily. I used this as an example in class:
coin = ['Heads - I win', 'Tails - you lose']
tosses = [choice(coin) for toss in range(1000)]
It was great. Very easy to understand. This combined with the 'count' method in a list, and I could go ahead and assign them a little HW project to create a frequency table for throwing 2 dice 10,000 times. I told them to just experiment, copy and paste their Shell session and email it to me. It worked very well. Even a lot of the kids who have been resistant to this Python stuff could handle it. Didn't require having to write functions - purely interactive.
Then the next day we explored tetrahedral and other kinds of dice.
Very simple, and it seemed to work well. There's a section at the end of the chapter that describes creating simulations using BASIC. Ha! We did this on the very first day!
- Michel