[Edu-sig] teaching python using turtle module
Edward Cherlin
echerlin at gmail.com
Sun Nov 29 23:51:14 CET 2009
On Sun, Nov 29, 2009 at 11:34, Brian Blais <bblais at bryant.edu> wrote:
> Hello,
> I was just playing with the turtle module, and thought it was an interesting
> way to augment the introduction to python (I teach college students, who
> haven't had any programming). It's a great way to introduce functions,
> for-loops, and general program structures.
If you use the Python-programmable tile in Turtle Art in Sugar, or
Smalltalk in the Turtle Graphics in Etoys, it's even better. I have
been doing presentations on teaching Python in elementary schools, and
working on how to teach basic Computer Science ideas. You can use an
if-then-else to initialize a stream in Python for the first pass, and
get a value at each pass thereafter. The logic can be either in the TA
or the Python.
> After a bit of playing, I realized that I couldn't think of many exaples
> which use turtle with conditional structures (if- and while- statements),
Repeat is used much more often. but of course we can provide examples
of any behavior you like. I like to use the turtle to generate
sequences, where I can use a conditional to stop when the turtle would
go off the screen. Fibonacci numbers, for example, or exponentials.
Similarly for spirals of various types. Simple cases like those are
easy to do in TA, while more complex sequences could use Python. There
are several fractal examples using loops provided with Sugar on a
Stick, including variations on Siepinksi constructions, and the Koch
Snowflake.
When I can get the code for reading the color of a dot on the screen
into the programmable tile, I can program a toy Turing machine, with
an array of dots as the transition table, and a line of dots as the
tape.
> or
> functions that return values, as opposed to "procedures" like:
> def square(length):
> forward(length)
> right(90)
> forward(length)
> right(90)
> forward(length)
> right(90)
> forward(length)
> right(90)
Surely you mean
repeat(4)
forward(length)
right(90)
> If-statements could possibly be used with some sort of random behavior (if
> rand()<0.5 ...).
Drunkard's Walk.
> Are there any other situations, using turtle, that these
> structures would be natural?
Recent versions of TA contain stack instructions: push, pop, read,
clear. Your students might find it interesting to program Forth
instructions in TA or Python. This has practical applications in
implementing and porting virtual machines such as Parrot and the VMs
in Smalltalk and I-APL.
There is plenty more where this came from. You would also be welcome
to adapt the Python source code for TA tiles to your environment.
> thanks,
> Brian Blais
> --
> Brian Blais
> bblais at bryant.edu
> http://web.bryant.edu/~bblais
>
>
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
--
Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin
Silent Thunder is my name, and Children are my nation.
The Cosmos is my dwelling place, the Truth my destination.
http://www.earthtreasury.org/
More information about the Edu-sig
mailing list