[Edu-sig] PyWhip - Keep on crackin' it!!

David MacQuigg macquigg at ece.arizona.edu
Mon Mar 9 00:44:03 CET 2009


At 08:41 AM 3/8/2009 -0700, kirby urner wrote:

>What I'm seeing at your site so far is a very low level workout in
>Python basics -- not a criticism in any way, just suggesting you could
>apply the same technique to more challenging problems.
>
>Here's one I like:
>
>Write a Python generator so you get successive rows of Pascals
>triangle, like this:
>
>o = Pascal()  # o for object
>>>> next(o)
>[1]
>>>> next(o)
>[1, 1]
>>>> next(o)
>[1,2,1]
>>>> next(o)
>[1,3,3,1]
>....
>and so on (Pascal's triangle).  Note I'm using Python 3.x syntax.
>
>One of the best solutions is:
>
>def pascal():
>        row = [1]
>        while True:
>                yield row
>                row = [i + j for (i,j) in zip([0]+row, row+[0])]

Nice!  If you don't mind, I'll use this in our category "math" at level-3.  It is more challenging than the level-1 we are focused on now, but the more advanced problems will come soon.

The idea is to organize the problems in layers.  Layer-1 is problems that don't depend on students knowing anything that isn't in a short help page on a specific topic, like strings.  Layer-2 can depend on knowing all the basic techniques in layer-1.  Thus, we can now ask string questions that are best solved with a loop.  Layer-3 would include the more challenging problems, like the one you are suggesting.

-- Dave 




More information about the Edu-sig mailing list