[Edu-sig] Python projects for CS1

kirby urner kirby.urner at gmail.com
Wed Mar 24 21:41:55 CET 2010

<< snip >>

Kirby wrote:

>>>>> p = "Able was I ere I saw Elba"
>>>>> e = encode(p, coding)
>>>>> e
>> 'AejlgfwtgIglclgIgtwfgEjew'
>>>>> decode(e, coding)
>> 'Able was I ere I say Elba'

Kirby replies:

First of all:  Happy Ada Lovelace Day!

Secondly:  Yikes!  I see the typo here (quoted above).

My actual IDLE session had some mistakes so when
I built up this posting, I cut and pasted the working bits,
but then kept this early wrong value for the plaintext p.

When p was enciphered / deciphered, it came back right,
i.e. decode(encode( p )) should be the identity function
for arbitrary p.  However, it started out with this 'say'
mutation, instead of 'saw'.  This is a famous palindrome
by the way, not invented by me, and is put into the mouth
of Napoleon Bonaparte for mnemonic purposes.

Anyway, apologies for my sloppiness to future readers
who might stumble on this post.

Just to expand a bit while I'm at it:

Allowing our permutations to be random instead of rotations
clearly makes this a rather large permutation space, so the
kind of brute force code cracking suggested in the exercise
would be harder.

Were MFTDA (Math for the Digital Age) to morph into a
series, with more time given to many of the topics (in addition
to new topics), then the ramp up to RSA could be more
leisurely and include such as the Caesar Codes in more

Rotations of polyhedra may be described with such mappings,
with starting / ending points of the vertices.  One might think
of two copies of the same polyhedron superimposed, with the
A of one going to the D of the other upon rotation, other
vertexes moving accordingly.  Permutations give a road map
between the different positions, showing what states are but
one hop away (thinking of hypertoons again -- another thread).

Over on math-teach today, I've drawn an analogy between the
digital divide separating traditional math classes from their
more digital counterparts, and the Berlin Wall.  I claim to be
echoing Ronald Reagan in demanding it be torn down.

(rather lengthy, might be called a rant).

I actually think just using Python as a calculator might
can take one a long way.  One might be projecting some
spatial geometric relationship, such as an icosahedron
with faces glued to an enclosing octahedron's, lots of
phi relationships to check.  This is exactly what I was
doing yesterday in fact.

Here's an excerpt from my email outbox:

Meant to include this Python excerpt (back of the napkin check on the
length he claims to find):

>>> from math import sqrt as radical
>>> phi = ( 1 + radical(5))/2.
>>> phi
>>> phi / radical(2)
>>> phi / radical(2) + radical(2) / 2


(18.51... == volume of C. in figure)

That length of the octahedron (icosahedron inside) is 1/10 the volume
of the enclosed icosahedron.  Curious.

Just thought I'd mention, given we're on the topic of the icosahedral
hubs in many versions of Flextegrity.

This might be a signature difference between using
Python in a math class versus a computer science class:
math students may make very light use of Python as
a calculator while focusing a lot of attention on problems
that do NOT require much if any programming to solve.

In other words, math students may often use Python
but do little or no programming with it -- not talking about
no programming in the whole course, just saying a whole
hour might go by where you just run Python as a scratch
pad on the side, have no need to compose or run
programs, other than to import from the occasional

More like Sage in some ways, except we may just
get by with IDLE or something similar.

I underline this difference for the sake of teachers who
cringe at the word "programming".  Some people went
into math teaching precisely because they didn't like
doing that, or just see it as adding a lot of overhead.

BTW, I think 3.1.2 is taken a significant step in its
numeric display habits.  The IEEE floating point
specification is not messed with, but repr has a new
set of conventions.  In general, number formatting is
getting more powerful.

When it comes to bulk data, you start to need more
programming just for file i/o, although even here you
might get away with a lot, especially if the module in
question pre-stores the data.

This is the Rich Data Structure idea I was talking about,
i.e. if you want students to have the lat/long for every
major city on Earth, or to have the Periodic Table of
the Elements as a dictionary of Atom objects (however
designed), then just include the bulk data as a part of
the module, already loaded up into these sophisticated

Or, if you wanna be more ambitious, include a Reader
for grabbing and loading from raw files, either locally
provided or over the wire (having these in addition to
"ready to use" would be most convenient).

I've got lat / long data for some cities at my web site,
along with a sample "capitals of states" quiz in
MySQL and simple Python.


You'll see if you read my rant that I go on about needing
a school server or rack of servers.  High schools may
not as yet have those, an unhappy truth.  Those that
do, though, will have an easy way to build up their
data stores.  Math students will get to study the source
code, help maintain it -- or do we call them computer
science students?  How much does it really matter?
Geometry + Geography = What?  Discrete math?

>> 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.


More information about the Edu-sig mailing list