[Edu-sig] Using IDLE with students

John Posner jjposner at snet.net
Wed Aug 22 04:28:52 CEST 2007


> When teaching Python to beginners and using IDLE, it seems that one of 
> the dangers would be to have them assigning variables in the 
> interactive mode and then maybe using them in a script they're 
> writing.  Then, when they run the script, the variable is still in 
> memory so the program works--for now.

   >> I run into this a lot, and I find that it's very very difficult to
explain
   >> what's going on to kids who are just getting their feet wet.

Not denying that RESTART vs. no-RESTART is an issue, but ... if you're going
to use IDLE in no-RESTART mode, why not reinforce the functionality as a
*feature*, not avoid it as a bug. The module window works more like a macro
than a self-contained program.

For example, a lesson might investigate the Fibonacci series like this:

1. In the interactive window, set up some initial conditions:

>>> a=1
>>> b=1
>>> count=2

2. Develop the following command sequence, by trial-and-error in the
interactive window, as the way to perform one Fibonacci iteration:

>>> a,b = b,a+b
>>> count = count+1
>>> print "Fibonacci term", count, "is", b
>>> print "ratio is", 1.0*b/a

During this trial-and-error process, it's very likely that the initial
conditions will need to be reestablished a number of times.

3. Use the interactive window's command-repetition capability (move the
cursor, then press Enter) to invoke the command sequence repeatedly,
generating Fibonacci iterations.

4. Invoke "New Window" and transcribe the command sequence into the new
module window:

a,b = b,a+b
count = count+1
print "Fibonacci term", count, "is", b
print "ratio is", 1.0*b/a

5. (SLIGHT GOTCHA) You must save the contents of the new module window in a
file.

6. Repeatedly invoke "Run Module", producing more iterations in the
interactive window:

>>> 
Fibonacci term 14 is 377
ratio is 1.61802575107
>>> 
Fibonacci term 15 is 610
ratio is 1.61803713528
>>> 
Fibonacci term 16 is 987
ratio is 1.61803278689
>>> 
Fibonacci term 17 is 1597
ratio is 1.61803444782
>>> 
Fibonacci term 18 is 2584
ratio is 1.6180338134
>>> 
Fibonacci term 19 is 4181
ratio is 1.61803405573


Each time you (click in the module window and) invoke "Run Module", the four
lines of code run in the current context of the interactive window.

And more:

* Use this repeated invocation of code to motivate "for" and/or "while"
loops.

* Describe the Golden Mean and compare the (converging) computed ratios to
the actual value. To compute the actual value, you must import the "math"
module.

Best to all,
John



More information about the Edu-sig mailing list