[Edu-sig] probability & simulation

2009-02-05 Thread michel paul
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
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Topics for CS2

2009-02-05 Thread Scott David Daniels

Scott David Daniels wrote:

Scott David Daniels wrote:
I wrote:


In PythonOOP.doc (page 4) you say:
 > There are two pieces of "magic" that make line 3 work.  First, the
 > interpreter has to find the method set_vars.  It's not in cat2.  Then,
 > the instance cat2 has to be inserted as the first argument to set_vars.
 > The method is found by a search starting at cat2 ( the instance on
 > which the method is called ).  The search then proceeds to the parent
 > class, then to the grandparent, and so on up to object, the ancestor
 > of all Animal classes.  In this case, we find set_vars in Cat.

For instances of subclasses of object (such as Cat), method lookups
start in Cat, not cat2.  If you try to set cat2.set_vars, you cannot
(because a method is a property stored in he class), and you will try
the set method of that property which will fail.  Simple class variables
are over-ridden by assignments to the instance values, but properties
are not.

This should be read/write properties are not.

And then immediately went to make a test case, which failed.  Which
I should, of course, done before hitting send.  I retract my comment
and will get back to you when I get my understanding straightened out.


And I just noticed a great thread on comp.lang.python addressing the
exact lookup order for obtaining attributes most recent post this
morning.  The Thread Title is "Understanding  Descriptors",
Brian Allen Vanderburg II asked the initial question, and Aahz and
Bruno Desthuillers came up with a thorough answer.
I'll put a link here, but it may wrap nastily.  Nickel summary, lookup
order is not dirt simple, and reading and writing work differently.

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a136f7626b2a8b7d/70a672cf7448c68e

--Scott David Daniels
scott.dani...@acm.org

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig