[Edu-sig] class notes (martian math)

kirby urner kirby.urner at gmail.com
Wed Aug 4 00:13:34 CEST 2010

I recently completed the 2nd day of this summer camp blitz
for TAG (talented and gifted) students, a category invented
by the district, and I'm not sure how it applies, i.e. this private
NGO has no obligation to check a district database for a
tag flag or anything, praise Allah.

Anyway, all the students are bright, astute, engaged and
interested.  Programming is hard fun and takes concentration.
One is lucky if able to muster it.  Takes a safe environment
and calories to burn.  We're in a campus of the highly privilege
where no expense is spared, and every kid has access to
a state of the art Apple.  I've got a projector and screen.
We all have Internet.

This is my first time to teach an all-Apple class and I have
to confirm Chairman Steve's impressing the IDLE is
languishing here.  Guido gave Python a tremendous boost,
propelled it into high visibility with an interactive Tk shell
and editor, but that infrastructure has not kept pace.  The
scroll bar tends to not work.  Resizing windows as they'll
get to large to fit the screen, so grabbing the lower right
resize control requires changing screen resolution through
the Finder control panel.

That being said, it's pretty amazing to have such a smooth
language co-functioning with VPython, such that we're
immediately able to get colorfun.py going, which the
students then tweak.  I'm using the 'heads first' or 'dive
into' approach of supplying plenty of scaffolding, getting
the results first, then going back over the syntax and
structure of the language with an eye towards making
small modifications.  We've spent a large percentage of
the last few hours tweaking color, learning about what's
canned (pre-named) and how to define your own RGB

Today, using the projector, I introduced the random module,
which I think is one of the first to be useful after visual itself.
random's randint and choice are two of the most practical.
Our code looks like this:

from visual import *
from random import randint

def galaxy( n ):
    for i in range(n):
        x = randint(-100, 100)
        y = randint(-100, 100)
        z = randint(-100, 100)
        r = randint(10)
        sphere( pos = (x, y, z), radius = r, color = color.red )

Then a next modification, after playing with choice and randint
in the shell a little more, and talking about lists, would be:

from visual import *
from random import randint, choice

colors = [ color.red, color.green, color.blue, color.yellow, color.orange ]

def galaxy( n ):
    for i in range(n):
        x = randint(-100, 100)
        y = randint(-100, 100)
        z = randint(-100, 100)
        r = randint(10)
        c = choice( colors )
        sphere( pos = (x, y, z), radius = r, color = c )

Once this code is working on each workstation (I go around to help catch
syntax errors, usually a missing comma or paren), then students might
vary the parameters, add more colors for example.

Earlier, when introducing functions more generally, I told the story
of the guy who impressed the king for a modest favor, were he
successful in a mission (the King put out an RFP and this looked
like the lowest bide):  put a grain of rice on the first square of the
chess board, double it for the next, and the next, and so forth.
"Can't be that much rice" thought the King.

def reward( ):
    therice = 0
    for x in range(64):
        therice = therice + 2**x
    return therice

Wow, all the rice in the world and then some, right?  Note that 2**0 == 1
and that's what goes on the first square, so we only get up to 2**63 on the
last square (with the rice being cumulative).

I continue to introduce ( ): in the function def as almost like an emoticon,
like two eyes with an open mouth.  Turn that mouth sideways to make it
look more like a mouth, and remember that's where to put your arguments.
This is easy to remember, as people use their mouths for arguing all
the time.

My students range in age from roughly 14-17.  My Photostream has a
few pictures from the current venue, mixed in with other topical photos
(a Flickr set):



More information about the Edu-sig mailing list