[Edu-sig] Python projects for CS1

kirby urner kirby.urner at gmail.com
Wed Mar 24 01:58:04 CET 2010


On Tue, Mar 23, 2010 at 7:29 AM, Bill Punch <punch at cse.msu.edu> wrote:

<< snip >>

> If you have any comments, we'd love to hear them.
>


Hi Bill --

I enjoyed poking through some of these, reminiscent of some of the
SuperQuest challenges for Oregon's annual software competition,
high school students working in teams, with a language of their
choice, to come up with a working solution in a time race.

I like how you cover a lot of territory.  Just looking at your page
reassures a student that computer programs are ubiquitous i.e.
in all walks a life (or a lot of 'em).  Teachers should feel heartened
as well, especially math teachers, seeking new relevance
amidst real world topics, like strangers in a strange land
(some of them).

I'm wondering if you sometimes revisit the same problem suggesting
different strategies for solution, perhaps after students have struggled
and turned in some work.  The same problem tackled multiple times
may help boost student self-confidence, as they perceive how their
powers are growing (like working out in a gym, lifting that same stack
more easily).

For example, the Caesar Code stuff is pretty interesting, as a generic
introduction to permutations, wherein rotations might be "multiplied".
You've got finite groups going here -- a topic I try to import from the
college math world, much of which hides behind "calculus mountain",
a killer peak most have to climb before they're even told "abstract
algebra" exists.  Yet so much fun could be had, so much cavorting,
if we could just play with "math objects" that play in groups.

http://www.4dsolutions.net/ocn/flash/group.html  (annoying noise!)

Another definition of a Caesar Code (Nero Code?  Hadrian Code?)
allows these codes to be completely random, though still one-to-one
of course, and includes the space character as another one to
encode, makes it all seem the more cryptic cuz of the wrecked
word boundaries.

So what if a student hasn't used dictionaries yet, or has only just
discovered them, and sticks with indexed strings, as your hints
suggest.  Coming back to the same problem later, newly armed
with a dictionary, list comprehensions, maybe the whole exercise
seems easier and more concise?  Don't wanna get *too* concise.

Example

IDLE 2.6.4

>>> from string import lowercase as lowers; from random import shuffle

Get lowercase a-z plus space character

>>> thechars = lowers[:26]+" "

>>> def makekey(instring):
	thecopy = list(instring)
	shuffle(thecopy)
	return dict(zip(list(instring), thecopy))

Build the secret key with thechars, get back a dictionary:

>>> coding = makekey(thechars)

>>> coding
{' ': 'g', 'a': 'x', 'c': 'w', 'b': 'c', 'e': 't', 'd': 'n', 'g': 'h',
'f': 'm', 'i': 'j', 'h': 'k', 'k': 'a', 'j': 'o', 'm': 's', 'l': 'u',
'o': 'p', 'n': 'l', 'q': 'y', 'p': 'z', 's': 'f', 'r': 'b', 'u': 'q',
't': 'i', 'w': 'e', 'v': ' ', 'y': 'r', 'x': 'd', 'z': 'v'}

Define encoding and decoding functions, then test them.  Pass through
any letters not in the key:

>>> def encode(phrase, secretkey):
	output = ''
	for char in phrase:
		output += secretkey.get(char, char)
	return output

>>> def decode(phrase, secretkey):
	output = ""
	reverselookup = dict((value, key) for key,value in secretkey.items())
	for char in phrase:
		output += reverselookup.get(char, char)
	return output

>>> p = "Able was I ere I saw Elba"

>>> e = encode(p, coding)
>>> e
'AejlgfwtgIglclgIgtwfgEjew'

>>> decode(e, coding)
'Able was I ere I say Elba'

My propensity, coming from a math teaching perspective, is to look
at a Python module as a "fish tank" with multiple mouths to feed,
i.e. I like to publish a simple API and feed arguments to functions
(other denizens) directly, sans raw_input prompts.

This more directly corresponds to the idea of a grab bag of tools,
a library, whereas a raw_input cycle more corresponds to polling
in a GUI, staying alert for user inputs.

Both modalities make a lot of sense, so I'm not saying I wouldn't
go with raw_input sometimes -- I know students like being prompted,
even by their own code.

Sometimes I even use text menus with switching. :)
http://www.4dsolutions.net/ocn/pymath.html  (example at the end).

Didn't see whether some of your challenges drop the raw_input
to seem more like libraries, or whether you ask for a menu.  Another
thing is to ask for command line arguments and use sys.args
-- so much fun, we might have, eh?

Anyway, we're all aware of these possibilities -- just thought I'd
remind myself of some of them.

Again:  reassuring to see the broad-based examples.

Hitting the same challenge multiple times, but with new tools
and/or concepts each time, is what many teachers call
"spiraling" as you likely know.

Pre-written code may be called "scaffolding" if you wanna
sound like you know the shoptalk.

In the high school math teaching world, John Saxon is often
cited for making especially strategic use of "spiraling"
although his detractors would consider this unmerited
crediting of an interloper (something of a maverick that
guy -- never met him).

I mention all this by way of background, in that I cite him
in my Notes for Teachers for Pycon 2009 re spiraling FYI:

http://www.4dsolutions.net/presentations/py4t_notes.pdf

On another note, thanks to Edward Cherlin (and Maria too)
for jumping in on math-thinking-l this month.  That's a
functional programmers' hangout and any incursion of
"imperative programmers" tends to generate some ire
-- kinda like West Side Story?  In the old days, we'd
find some eligible prince or princess to marry into the
Great Lambda tribe (as in lambda calculus).

I've been bugging philosophers to devote some bandwidth
to this feuding but they're busy with paper and pencil logic,
can't be bothered with "CS" apparently.

Maybe I'm being overly judgmental, and anyway it's not like
there's anything much at stake.  Or is there? -- math teachers
like Maria get caught in the cross-fire, Gary too for that
matter, though he seems to hold his own.  Maybe the
floodgates would open for more funding of discrete maths
at the high school level, if only the engineers weren't seen
to be fighting amongst themselves so much?  Nothing scares
away wannabe investor-sponsors so much as feuding and
acrimony eh?

Speaking of Gary (Litvin), he got the ball rolling by commenting
on corestandards.org, a K-12 standards-building initiative
purportedly with real state governors on board.  He sees signs
that discrete math topics are losing ground, not gaining it.
But that's perhaps more testament to an unimaginative
and uninformed bureaucracy that has yet to achieve
a strangle-hold?  One may fondly so hope I suppose. Over
on math-teach, I mention that our Pauling Center has not
been consulted, and we're at the epicenter (evidence that
these bureaucrats have gone way out on a limb?).

http://mathforum.org/kb/message.jspa?messageID=7013136&tstart=0

See math-thinking-l archives if wanting more substance
behind these ramblings (wanderings).

Bill, if you're still with me, I look forward to poking around
in more of your exercises and may well have more to say,
hope OK.

Kirby


More information about the Edu-sig mailing list