Re: [Edu-sig] More practice exercises

2011-06-11 Thread Gregor Lingl

Am 11.06.2011 19:54, schrieb kirby urner:


I've been looking these over since reading your post.  I'd heard of 
this project but this was my first time to really check it out.


...

Thanks for these links.  Python should be fast enough to get within 
the one minute time frame one would think, at least on some of them.
It is definitely! I got a solution to problem 341, that needed less the 
15 seconds.
I've no solution to 342 yet. As "your" Euler totient is the central 
point of the problem, I thought this is your thing - and you can't help 
to solve it   ;-)


Best wishes
Gregor


Kirby


On Sat, Jun 11, 2011 at 9:26 AM, Gregor Lingl <mailto:gregor.li...@aon.at>> wrote:


A very interesting collection of exercises you can find on

http://projecteuler.net/

Especially the problems below 100 are well suited for beginners.

http://projecteuler.net/index.php?section=problems

This week's problem, on the contrary, seems to be customized for
Kirby!

http://projecteuler.net/index.php?section=problems&id=342
<http://projecteuler.net/index.php?section=problems&id=342>

Best regards,
Gregor


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] More practice exercises

2011-06-11 Thread Gregor Lingl

A very interesting collection of exercises you can find on

http://projecteuler.net/

Especially the problems below 100 are well suited for beginners.

http://projecteuler.net/index.php?section=problems

This week's problem, on the contrary, seems to be customized for Kirby!

http://projecteuler.net/index.php?section=problems&id=342

Best regards,
Gregor
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Anyone interested in discussing the turtle module?

2011-06-01 Thread Gregor Lingl

Hi Jeff,

I think Corey's solution is the canonical one and quite ok.

Just a few remarks concerning the your problem and the turtle module.

1. The present solution for the turtle.Screen() window was introduced by
Vern Ceder for the previous module (as far as I rembmber) and had to be
retained for upward compatibility reasons.

2. I'm also finding the inability of turtle.Screen() to take screen size 
arguments

a deficiency. So you could propose your idea to the python issue tracker
(or if  you prefer I could do this also). This will be relevant for 
Python 3.3 only
but I'm definitely interested to implement additions and amendments like 
this.

(According to the Python 3.3 release schedule, this must be done until
June. 23rd 2012 (!). This should be no problem.)

3. There is (at least) one more way to adjust the initial screensize, 
namely by

putting an appropriate entry into a turtle.cfg file. You can customize some
more properties with this file). See

22.1.6.3  How to configure Screen and Turtles in the Python-Docs:

http://docs.python.org/library/turtle.html#how-to-configure-screen-and-turtles

I used this for my book "Python für Kids" where I wanted a consistent 
appearance of the turtle window.


4. There are essentially only two classes to be used from the turtle 
Module.


So if you want to work object-based, it is possible to do this by

from turtle import Screen, Turtle

I found this to be a bit less verbose and also useful in order to avoid 
confusion of
module turtle and class Turtle. (I think to some degree this is a matter 
of taste)


5. Probably you will stumble about some other weird features of the 
module or

have some bright ideas for amendments or you will have some more questions
converning turtle.py. I'm definitely wanting to discuss these with you 
and others.

Perhaps we could arrive at a still better turtle module for Python 3.3.
(But please keep in mind the compatibility requirements for modules in the
standard library).

Best regards

Gregor Lingl

Am 31.05.2011 22:59, schrieb Jeff Elkner:

Hi All,

I'm working on an introductory CS book using Python with the turtle
module, but I'm finding the inability of turtle.Screen() to take
screen size arguments to be a real pain.  The screen size appears to
depend on the screen size of the host environment, which means
standardizing screen shots for the book becomes impossible.

Any thoughts on this issue?  It would be a huge help in promoting
Python's use in education if we could make use of such a potentially
fine module as the turtle module, but I'm finding it very difficult to
write curriculum materials that use it since students don't have
control over the turtle's screen in any easy to use way.

Thanks!

jeff elkner
open book project
http://openbookproject.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] (egyptian fractions...) the turtle part: chaos.py

2011-06-01 Thread Gregor Lingl



Am 01.06.2011 22:52, schrieb kirby urner:


Hey Jeff, your question about controlling the turtle's screen
might have been just the ticket in my attempts to control
chaos, namely G. Lingl's chaos.py, which demonstrates
sensitivity to initial conditions is a plus if you want your
algebra to stay on the same page as itself, per equalities
that won't be equal in the real world.  I'm hoping to throw
that into site-packages on the back end at OST, along with
all those baseball stats in SQL.  It's all done with turtles
(Gregor's thing) and is brilliant, here's a link:

http://www.4dsolutions.net/ocn/python/OST/chaos.py



Hi Kirby,

it's fine that you "host" a slightly amended version of chaos.py
on your website.

The original file is part of the demo that ships with Python and
the turtledemo has been moved into  the Lib-directory of the
standard distribution.

Some of these demo-scripts suffer from (more or less minor :-) )
quirks or deficiencies and could be amended in this or that way.

I think that such amendments should go into Python 3.3. So if
you or anybody else have any ideas, complaints or - as shown here -
propositions or results, please let's discuss them, so the turtledemo
can obtain not only a demo- but also an enhaced educational value.

Best regards

Gregor


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] superformula, generators

2011-05-21 Thread Gregor Lingl

Hi all,

recently I stumbled (once more) over a posting by our friend
Daniel Ajoy about the superformula (I think it was in a Logo-Forum):

http://en.wikipedia.org/wiki/Superformula

On the other side Kirby wrote interesting suggestions
about using generators.

Now, weekend, bad weather, some sparetime, I
assembled an implementation of a superformula-viewer
using pygame. It runs with Python 2.6 or higher, also
3.x, of course

You'll find it here for download:

http://dl.dropbox.com/u/2016850/superformula.py

or appended (which sometimes / for some of you)
doesn't work well depending on the browser or whatever.

The script uses generators for generating the pointlists
of the graph of the superformula and also for generating
colors for the segments of the graph-area.

Morover I've prepared a q&d slider class, which possibly
doesn't use the canonical way of processing events in
pygame but works fine for this application.

Critical comments and feedback and also questions, of course,
are welcome.

Perhaps someone is willing to amend the docstrings,
which suffer from my clumsy English and could well
be more clear.

Amendments of the code, espercially ones, which make it
more readable and easier to understand, also.

Useful for classroom use? Perhaps to difficult?

Best regards,
Gregor


# Autor: Gregor Lingl
# Superformula
# http://en.wikipedia.org/wiki/Superformula
# Version: 1.0  for Python 2.6 or higher; for 3.x also (!)
# Date: 2011-05-21

from math import sin, cos, pi
import sys
import os
import pygame
import random

os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()

SCREEN_SIZE = (SX, SY) = (540, 750)
CX, CY = 270, 270
R = 250

# colours
RED = (255, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0)
BLACK = (0, 0, 0)

# more ressources
CLOCK = pygame.time.Clock()
SMALLFONT = pygame.font.SysFont("Lucida Console", 12)
SMALLFONT.set_bold(True)
DEMO_TITLE = "SUPER-FORULA"

class Slider:
"""Sliders of this class change values in the mutable value_list argument.
   If fl=True, the slider sets floatingpoint-values, otherweise integer 
values.
"""
def __init__(self, surf, left, top,
 name, minval, maxval, value_list, defaultval = None, fl=True):
"""Slider-Position: (left, top) on surf
   name is used to label the Slider,
   Determine from the length of value_list the index of the
   values the slider sets, and append a default-value to value_list.
"""
self.surface = surf
self.name = name
self.minval = minval
self.maxval = maxval
self.values = value_list
self.index = len(value_list)
self.fl = fl
if defaultval is None:
self.val = (minval+maxval) / 2
else:
self.val = defaultval
if not fl:
self.val = int(round(self.val)) # int() for compatibility with 2.7
value_list.append(self.val)
self.image = pygame.Surface((240, 50))
self.left = left
self.top = top
self.marker = int(round(20 + (self.val - minval) * 200 / (maxval - 
minval)))
def value(self):
"""Calculate value from marker position.
"""
v = self.minval + (self.marker - 20) * (self.maxval - self.minval) / 200
return v if self.fl else int(round(v))
def draw(self):
"""Draw the slider, its label and its value to self.surface.
"""
self.image.fill((32, 32, 32))
pygame.draw.rect(self.image, YELLOW, (0, 14, 239, 35), 2)
pygame.draw.line(self.image, GREEN, (20, 32), (220,32), 3)
pygame.draw.circle(self.image, RED, (self.marker, 32), 12)
val = (": {0:3.1f}" if self.fl else ": {0}").format(self.value())
text = SMALLFONT.render(self.name + val, True, BLACK, YELLOW)
w, h = text.get_size()
w += 12
h += 5
ts = pygame.Surface((w,h))
ts.fill(YELLOW)
ts.blit(text, (6, 3))
self.image.blit(ts, (10, 0))
self.surface.blit(self.image, (self.left, self.top))
def process(self, event):
"""If mouse is on slider-marker, left mouse-button is pressed
and mouse is moved, change marker-position and value in value_list
accordingly.
"""
if event.type != pygame.MOUSEMOTION or event.buttons[0] != 1:
return
x, y = event.pos
x -= self.left
y -= self.top
if (x - self.marker)**2 + (y - 32)**2 < 12**2:
self.marker = min(max(20, x), 220)
self.values[self.index] = self.value()

def superformula(params):
"""Calculate graph (list of paris of coordinates) for superformula from
http://en.wikipedia.org/wiki/Superformula
M, N1, N2, N3 are

Re: [Edu-sig] some notes and links

2010-09-01 Thread Gregor Lingl


kirby urner schrieb:

Hey good news about numpy now supporting Python 3.  Some of you will
have seen that announcement.

I'm getting ready for DjangoCon here in Portland, am likely to be
'snake handler' again this year, carry the PSF totem around, a token
of friendship when she meets up with Djangopony.

I've been looking at some of the swoopy effects in HTML5, thinking
about the future of trucking software, such as transportation system
managers.

http://controlroom.blogspot.com/2010/08/tomorrows-guis.html
http://controlroom.blogspot.com/2010/08/notes-on-trucking.html

http://www.thewildernessdowntown.com/  

This is really a great demo

...
Given my Geometry + Geography paradigm, I see trucking mixing with
Google Street View as a way to learn more about a given topography
  
We have a big discussion in Europe at the moment (especially Germany and 
Austria) concerning the question if google streetview is legal in our 
countries or should be restricted/forbidden.


Concerning html5 and given your Geometry + Geography paradigm you might 
want to have a look at what can be done with the htlm-canvas element alone:


http://www.phpguru.org/html5-examples

Regards,
Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] turtle in education

2009-12-20 Thread Gregor Lingl



roberto schrieb:

On Fri, Jul 31, 2009 at 12:48 PM, Gregor Lingl wrote:
  

Hi Roberto, hi all,

I've just created a repository of turtle graphics demos/applications
at google code:

http://code.google.com/p/python-turtle-demo/



thank you Gregor !
I am back to office now and read your news

i'll take carefully into account your material;

also i'll try to differentiate the ways for my students using Sugar
TurtleArt as a start-up (and ongoing) tool and your Turtle module as
an ongoing one for more experienced guys;

it will take me some time but i'll contribute everything may help
others in the field
  

Hi Roberto,

did you already arrive at some results/conclusions concerning the use of 
turtle.py?


Best regards,
Gregor
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread Gregor Lingl



kirby urner schrieb:

I'm glad turtle graphics intersected my thinking re extended precision
decimals (Decimal type) on edu-sig just now.

I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod:

http://www.4dsolutions.net/ocn/python/tmod.py (runnable source)
http://www.flickr.com/photos/17157...@n00/4147429781/  (GUI view)
  

Nice tiny app! Albeit not an example for using the if statement ;-)
Just to show you how turtle.py enables you to implement this
using quite different approaches to doing geometry, I'd like to add
two more implementations.

Besides you may notice that these do not rely on rather complicated
calculations of distances and angles, using the Pythagorean theorem
and trigonometrics but only on a few more fundamental properties of
the figure.

# Version 2 - using coordinate geometry without coordinates ;-)
# a different implementation for Kirby's "Plane Net for T-module"

from turtle import *
from math import sqrt

PHI = (sqrt(5)-1)/2

def planeNet(h=500): 
  setup(560,560)

  title("Plane Net for T-module")
  penup()
  back(h/2); left(90); back(h/2); right(90)
  pendown()

  forward(h); left(90)
  forward(h*PHI); A = pos(); forward(h-h*PHI); left(90)
  forward(h*PHI); B = pos(); forward(h-h*PHI); left(90)
  forward(h); C = pos()

  for P in A, B, C:
 goto(P)


# Version 3 - stamping simple transforms of the shape of
#  an isosceles rectangular triangle:

from turtle import Screen, Turtle
from math import sqrt

GOLDEN_RATIO = (sqrt(5)-1)/2

def planeNet(h=500.0, phi=GOLDEN_RATIO): 
  s = Screen(); s.setup(560,560); s.title("Plane Net for T-module")

  s.register_shape("recttriangle", ((0, 0), (h, 0), (0, h)))
  designer = Turtle(shape="recttriangle")
  designer.color("black","")
  designer.penup()
  designer.goto(-h/2, h/2)

  for width, height in ((1, 1-phi), (phi, 1-phi), (phi, 1)):
 designer.shapesize(width, height)
 designer.stamp()
 designer.forward(h)
 designer.right(90)
  designer.hideturtle()

Hoping, you will find this a bit interesting,
best regards

Gregor




Here's the graphical output:

http://www.flickr.com/photos/17157...@n00/4148139184/in/photostream/
(Python 3.1)

If you actually wanna fold the T, you need to snip off the cap and
reverse it, per this diagram:

http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html

120 of them, 60 folded left, 60 folded right, all of volume 1/24, make
the volume 5 rhombic triacontahedron.

http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html

If you blow up the volume by 3/2, to 7.5, the radius becomes phi /
sqrt(2) -- what we're showing with Decimals.

The reason this seems unfamiliar is the unit of volume is the
tetrahedron formed by any four equi-radiused balls in inter-tangency.

I'm spinning this as Martian Math these days, yakking on
math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et
al.

Kirby

  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread Gregor Lingl

Hello Brian,

I think the most natural use of the if statement (using turtle
graphics) occurs in recursive functions drawing trees,
fractals and the like. This is well known from Logo, where
recursion is the canonical way of doing repetitions. (But
note, that Logo has tail recursion optimizaton!)

If you are not yet ready to use recursion with your students,
probably many  of the problems coming to your mind that need
the examination of conditions  can be solved better by using
a conditional loop (i. e. a while -loop in Python) than by
using mere if statements.

That is not the case however, if you have to perform actions in
the body of a loop, that depend on the current situation.
I did a quick search in my repository of examples and found
a fairly short and simple script that demonstrates, what I mean:
a drunken turtle collecting coins (or whatever) on its random walk.


# Python script using turtle graphics

from turtle import Screen, Turtle
from random import randint

s = Screen()
s.setup(560,560)
s.title("A drunken turtle collecting ...")

s.tracer(False)
writer = Turtle(visible=False)
writer.penup()
writer.goto(0, -275)

coins = []
for i in range(-4,5):
   for j in range(-4, 5):
   if i == j == 0:
   continue
   c = Turtle(shape="circle")
   c.color("", "orange")
   c.shapesize(0.5)
   c.goto(40*i, 40*j)
   coins.append(c)
s.tracer(True)

DRUNKENNESS = 45   
t = Turtle(shape="turtle")

t.color("black","")
points = 0
while abs(t.xcor()) < 200 and abs(t.ycor()) < 200:
   t.forward(5)
   t.right(randint(-DRUNKENNESS, DRUNKENNESS))
   found = None
   for c in coins:
   if t.distance(c) < 10:
   found = c
   break
   if found:
   found.hideturtle()
   coins.remove(found)
   t.shapesize(1+points/5., outline=1+points)
   points += 1

writer.write("{0} points".format(points),
align="center", font=('Arial', 24, 'bold'))

## End of script


You can see a screenshot of a run of this script here:

http://www.dropbox.com/gallery/2016850/1/TurtleCollector?h=6b370a

The script could be expanded in several ways, e. g. for
doing statistical investigations or examinig how the
result depends on different parameters like drunkenness etc.
Or you distribute the coins randomly ... Does that alter
the average "harvest"?

Just a suggestion ...

Regards,
Gregor


Brian Blais schrieb:

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.


After a bit of playing, I realized that I couldn't think of many 
examples which use turtle with conditional structures (if- and while- 
statements), 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)


If-statements could possibly be used with some sort of random behavior 
(if rand()<0.5 ...).  Are there any other situations, using turtle, 
that these structures would be natural? 




thanks,

Brian Blais

--
Brian Blais
bbl...@bryant.edu 
http://web.bryant.edu/~bblais 





___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig
  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] thought re graphing calculators ...

2009-09-29 Thread Gregor Lingl



kirby urner schrieb:

On Tue, Sep 29, 2009 at 9:15 AM, Gregor Lingl  wrote:
  

Strategy of escalation? Arms race?




Not so much.  There's nothing on the other side.  Will anyone do this
manually?  Is that what "correctly" means?  More likely they mean
something like "symbolically" which is akin to "just imagining
something without really doing any of the work" (so no contest, I walk
away happy).

The ability to brute force these data points with a self-feedback
circuit governed by various expressions, is for computers and
computers only.  Humans by themselves aren't even in the game.  At the
very least you'll want an abacus, or lowly calculator if you're a nerd
(snicker).
  
Oh no, when thinking about calculations or even only viewing diverging 
graphs humans not

only are in the game but are still its main characters.

Since say 5000 years humans have devoloped the concepts of numbers, 
calculations and
algebra. They have discovered, that calculations obey certain algebraic 
laws like
a*(b+c) = a*b + a*c and the like. Finally they have devoloped the 
concepts of

algebraic structures like rings, fields etc.

The purpose of my script simply is to show, that  what we know as real 
numbers are
different things  (entities) than what we have invented (using nature an 
physical phenomena)
as machine numbers. These two simply obey different sets of algebraic 
laws. The distributive
law is not valid for machine numbers with the operations + and *. And 
this statement is true

independent from the setting for getcontext().prec.
(Floating point) machine numbers with + and * do not form a field. To 
describe their

behaviour you have to devise different algebraic structures.

This is not a gewgaw!

In fact my intentions are much less ambituous. I'd be very glad if even 
50 % of my
students accepted seriously that the squareroot of two does not equal to 
1.41421356237.
They do not, regardless of the fact that they are able to multiply this 
number with itself

by hand (!) and to recognize that  the result  does not equal 2.

from turtle import *
from decimal import Decimal, getcontext
getcontext().prec = 50

k = Decimal('3.9')

N = 250

That's what I meant with (in principle)

Gregor




Yes, I understood.  But what's the principle?

In my curriculum, we worship nature and physical phenomena a lot more,
  
Usually, e. g. when explaining the butterfly effect (does one use this 
term in English?), on argues
that long-term forecasting the future is impossible because of necessary 
inaccuracies of the
initial values as results of measuements. But look precisely: in the 
example we talk about,
there are no measurements, which can be inaccurate and the initial 
values are well defined.
It's the mathematics of machine numbers which generates - after a 
sequence of only a few
hundred arithmetic operations - results, which are completely senseless 
(or lack any meaning).

If you don't mind,  ok. But you have to admit it.

That is not the case with ordinary numbers.

so this imaginary thing where you imagine the same curves out to
infinity, but don't actually plot anything, who worthless is that?  
A very dangerous argument, in my opinion. Many (if not most) 
mathematicians agree with
the statement that one of the most central concepts  of mathematics - 
and the one concept

which makes mathematics interesting - is the concept of infinity.
If not one had to abandon  a large part of classical mathematics.

To think, people actually get paid for such daydreaming.  Amazing.
  
Now I stared at this sentence for about 10 Minutes but I can't figure 
out what you wanted
to express exactly with this phrase. Don't know if it is my limited 
knowledge of the English language,
my lack of getting the irony or simply my inability to accept the point 
of view of the

modern geometrician, who anly accepts as real what he can visualize.

Gregor

Kirby

  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] thought re graphing calculators ...

2009-09-29 Thread Gregor Lingl



kirby urner schrieb:

On Mon, Sep 28, 2009 at 4:03 PM, kirby urner  wrote:
  

On Mon, Sep 28, 2009 at 3:12 PM, Gregor Lingl  wrote:


...
That's fine (for the turtle). But if someone thinks that everything is
calculated
"correctly" now, she/he is bound to get disappointed. And that's the point
(imho).

  

Yes, it's a philosophical point.  Doing it manually would be error
prone so the "correct" way is more science fiction or fantasy than a
reality.

The older ways of teaching math set up some false expectations, and
then when reality fails to make good, reality gets blamed, instead of
the broken metaphysics behind much of "modern" math.

Kirby

    

Regards,
Gregor


# Author: Gregor Lingl
# amended to use Decimal by Kirby Urner 2009-09-28
# re-corrupted to show the vainness (in principle) of kirby's effort
  

# fixed to show robustness of engineering solutions vs. imaginary
superpowers of non-existent math gods
  

2009-09-28
# Date: 2009-06-24

# A demonstration of chaos

from turtle import *
from decimal import Decimal

  


from turtle import *
from decimal import Decimal, getcontext
getcontext().prec = 50

:)

Kirby

  

Strategy of escalation? Arms race?

from turtle import *
from decimal import Decimal, getcontext
getcontext().prec = 50

k = Decimal('3.9')

N = 250

That's what I meant with (in principle)

Gregor
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] thought re graphing calculators ...

2009-09-28 Thread Gregor Lingl



kirby urner schrieb:

Hi Brian,



This ran perfectly on Python 3.1rc1 (r31rc1:73069, May 31 2009,
08:57:10) on my WinXP box (one of a few).

Note:  if this level of chaos / noise bothers you (the functions are
algebraically the same, after all), then I recommend using the decimal
type instead of the floating type, converting to float just to make
your turtle happy:
  
That's fine (for the turtle). But if someone thinks that everything is 
calculated
"correctly" now, she/he is bound to get disappointed. And that's the 
point (imho).


Regards,
Gregor


# Author: Gregor Lingl
# amended to use Decimal by Kirby Urner 2009-09-28
# re-corrupted to show the vainness (in principle) of kirby's effort 
2009-09-28

# Date: 2009-06-24

# A demonstration of chaos

from turtle import *
from decimal import Decimal

k = Decimal('3.9')

N = 160

def f(x):
x = Decimal(str(x))
return k*x*(1-x)

def g(x):
x = Decimal(str(x))
return k*(x-x**2)

def h(x):
x = Decimal(str(x))
return k*x-k*x*x

def jumpto(x, y):
penup(); goto(x,y)

def line(x1, y1, x2, y2):
jumpto(x1, y1)
pendown()
goto(x2, y2)

def coosys():
line(-1, 0, N+1, 0)
line(0, -0.1, 0, 1.1)

def plot(fun, start, colour):
pencolor(colour)
x = start
jumpto(0, x)
pendown()
dot(5)
for i in range(N):
x=fun(x)
goto(i+1,float(x))
dot(5)

def main():
reset()
setworldcoordinates(-1.0,-0.1, N+1, 1.1)
speed(0)
hideturtle()
coosys()
plot(f, 0.35, "blue")
plot(g, 0.35, "green")
plot(h, 0.35, "red")
# Now zoom in:
for s in range(220):
setworldcoordinates(0.5*s,-0.1, N+1, 1.1)
return "Done!"

if __name__ == "__main__":
main()
mainloop()

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] thought re graphing calculators ...

2009-09-28 Thread Gregor Lingl



Brian Blais schrieb:

On Sep 27, 2009, at 19:38 , Charles Cossé wrote:

Hi, this has probably been discussed to death already, but maybe not: 
The point at which fancy graphing calculators become "necessary" (ie 
as in one's student career) is the point at which the calculator 
should be abandoned and Python employed.  Just a thought ... delete 
at will !


Just a month ago, a friend of mine who homeschools her children was 
asking me about graphing calculators.  Apparently the math curriculum 
she uses has a number of graphic calculator exercises.  My advice was 
to buy a nice solar-powered scientific calculator (for $15 at Target), 
but to ignore the graphing calculator entirely.  Her kids should do 
the exercises by hand, on graph paper instead.  Anything that is hard 
enough for you to use a graphic calculator can be done much more 
easily with a computer.  

After giving her this advice (which I still stand by), I was thinking 
about my own experience.  I was going through high school when the 
first graphic calculators came out, and I had one Junior and Senior 
year and through college.  I loved to program it, and I loved the big 
screen where I could see and edit expressions.  However, as I think 
about it, I can not think of a single problem where I *needed* the 
graphic calculator, or where it gave me more insight than I could do 
by hand. 

Hi Brian,

I think I have a counterexample.
Run the script, that you can find here:

http://svn.python.org/view/*checkout*/python/branches/release26-maint/Demo/turtle/tdemo_chaos.py?revision=73559&content-type=text%2Fplain

(or below.) Runs with Python 2.6 or later.
It certainly could be mimicked on
a (programmable) graphics calculator.

What do you think?

Regards,
Gregor

# File: tdemo_chaos.py
# Author: Gregor Lingl
# Date: 2009-06-24

# A demonstration of chaos

from turtle import *

N = 80

def f(x):
   return 3.9*x*(1-x)

def g(x):
   return 3.9*(x-x**2)

def h(x):
   return 3.9*x-3.9*x*x

def jumpto(x, y):
   penup(); goto(x,y)

def line(x1, y1, x2, y2):
   jumpto(x1, y1)
   pendown()
   goto(x2, y2)

def coosys():
   line(-1, 0, N+1, 0)
   line(0, -0.1, 0, 1.1)

def plot(fun, start, colour):
   pencolor(colour)
   x = start
   jumpto(0, x)
   pendown()
   dot(5)
   for i in range(N):
   x=fun(x)
   goto(i+1,x)
   dot(5)

def main():
   reset()
   setworldcoordinates(-1.0,-0.1, N+1, 1.1)
   speed(0)
   hideturtle()
   coosys()
   plot(f, 0.35, "blue")
   plot(g, 0.35, "green")
   plot(h, 0.35, "red")
   # Now zoom in:
   for s in range(100):
   setworldcoordinates(0.5*s,-0.1, N+1, 1.1)
   return "Done!"

if __name__ == "__main__":
   main()
   mainloop()




It was a fun toy, but not the best tool.



bb



--
Brian Blais
bbl...@bryant.edu <mailto:bbl...@bryant.edu>
http://web.bryant.edu/~bblais <http://web.bryant.edu/%7Ebblais>





___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig
  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Beautiful sample programs?

2009-09-28 Thread Gregor Lingl

Hi Hélène,

I'd like to point you to a suite of sample scripts
that use Python's turtle module. You can find it here:

http://python-turtle-demo.googlecode.com

It contains a demo-viewer turtleDemo.py that lets you
inspect the source code of the example scripts and execute them.

So you get an overview about what is offered very easily and
quickly.

Moreover there are a couple of scripts that are designed to run
standalone, among them a towers of hanoi animation,
a gravitational system simulation and the trigeo.py
script mentioned by Kirby in a previous posting.

Regards,
Gregor


Helene Martin schrieb:

Hello,

As some of you know, I teach high school classes in Seattle.  Students
have been loving Python so far!  They've been able to dive right in
and get some interesting results.

I was wondering whether any of you had suggestions for Python programs
to look at, dissect, extend and emulate.  I'm looking for something
reasonably small like a simple music player, some kind of calculator
app, a collection manager or something like that.  I'd rather it be an
existing open source project someone started out of necessity (rather
than me creating something contrived for the exercise).  I've poked
around a bit but haven't found anything I thought would be perfect
either because of scale (I'd rather keep it to a handful of files),
complexity or just plain code ugliness.

Any suggestions would be appreciated.

Hélène Martin.
http://garfieldcs.com
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Another idea of Conway

2009-09-13 Thread Gregor Lingl



Maria Droujkova schrieb:

This language looks like a lot of fun. Especially given the fact none
of students coming to me for the first time (or their parents) can't
typically find any use of fractions beyond cooking, if that. Are there
some beginner, hands-on/visual or otherwise "more accessible" examples
for it? What fun!

  

Unfortunately I don't know of any. There is a chapter on Fractran in

Julian Havil: Nonplussed!: Mathematical Proof of Implausible Ideas
http://www.amazon.com/Nonplussed-Mathematical-Proof-Implausible-Ideas/dp/0691120560 



It contains a nice proof of the fact that that 'fractran-program' 
calculates exactly the primes.
Although perhaps "more accessible" it still assumes some computer 
science background.


And, yes, it's fun. But as it happens so often with fun, it's useless - 
in contrast to cooking ;-)   ,

which may be fun also, though.

You have to calculate 281 integers to arrive at 32, which delivers the 
prime 5 and

710 integers to arrive at the next prime: 7

Best wishes
Gregor

P.S.: I like your homepage. Think I should register to find out more
about what it's all about.


Cheers,
Maria Droujkova
http://www.naturalmath.com

Make math your own, to make your own math.





On Sun, Sep 13, 2009 at 8:08 AM, Gregor Lingl  wrote:
  

Although my posting to this list seems to tend to become
a somewhat autistic activity I'd like to reveal the 'mystery'
behind the script below:

http://esolangs.org/wiki/Fractran
http://en.wikipedia.org/wiki/FRACTRAN

Would writing a fractran interpreter in python be an interesting
project for teaching CS? (My first try below allows for a lot of
optimizations, e.g. not to use Fraction but resort to (long) ints.)

Best wishes,
Gregor

Gregor Lingl schrieb:


Hi all,

on vacation in the Tyrolean Alps one evening
I've found the time to implement another (I assume
less well known) idea of John Conway.

Just for fun.

from fractions import Fraction

fracs = [Fraction(f) for f in
 "17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11 15/14
15/2 55/1".split()]

def fracgame():
  z = Fraction(2,1)
  while True:
  for f in fracs:
  n = z * f
  if n.denominator == 1:
  break
  yield int(n)
  z = n

def pow2(z):
  n = 0
  while z % 2 == 0:
  n += 1
  z //= 2
  return (z == 1) * n
 def what():
  fg = fracgame()
  while True:
  z = next(fg)
  n = pow2(z)
  if n != 0:
  yield n

what = what()
print(next(what))
print(next(what))

# the following will take 1 or 2 minutes

##w = 0 ##while w < 100:
##w = next(what)
##print(w)

Comments or discussion may follow when
I'm back to Vienna.

All the best,
Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig




  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] casino math (unit three) (Saturday night fever)

2009-09-13 Thread Gregor Lingl

Laura Creighton schrieb:


I have to think about this more, but on a very quick first reading it
seems that you have missed a strategy that I have needed in order to
solve some tough PileOn games.

And that is breaking up groups of 2 or 3 that you already have built, or 
dealt.  Given these 3 piles to start with


A B X X
C D X E
F G X B
(and then some more)
  

This pattern does not occur in my sample configuration:

   (   (11,  6,  2,  1),
   (11, 10,  4,  1),
   ( 9,  2,  6,  3),
   ( 9,  4,  8,  3),
   ( 7, 12, 10,  5),
   ( 7, 12,  2,  5),
   ( 5,  8,  4,  7),
   ( 5,  6, 12,  7),
   ( 3, 10,  8,  9),
   ( 3,  2,  6,  9),
   ( 1,  4, 10, 11),
   ( 1,  8, 12, 11),
   (13, 13, 13, 13),
   (),
   ())

it has only even ranks in the second and third column, occurring
pairwise in these columns, and odd ranks in the fourth one.
(The thirteenth row is out of the game) So initially there are no
three equal ranks in the third column and no X occurring in the
second or third column can appear in the fourth.

the correct way to solve things may be to put E and B in the empty
slots, take one X  from the first pile and put it on the second
and take the other and put it on the third.  Then move the B
from the empty slot back to pile one.  

This also does not occur in my initial configuration, as some B
in the fourth column can only reappear in the first one and not
in the second one. One (ond only one) move combining a seven from
the first column with two sevens from the fourth one appears in
my proof of non-solvability of this layout.

The same thing has also
been needed when piles are

A X X B 

Also this pattern does not occur: each row has only two different
even ranks. Of course only an a bit closer investigation (as
discribed in my pevious posting) shows that these patterns also
do not occur during the game.


as well.

Does your algorithm handle that, or does it assume that things that
are stuck together belong together?

No this is not assumed.

I do not have a special algorithm to solve Pile On, but only search
the game tree using backtracking. Normally that gets out of hand.
The point is that I believe to have found one *special* layout that
can be investigated completely by hand, because due to its
symmetries there occurs only a very limited set of possible moves.

I think, that still some labour is needed to retrace my arguments.
But if you are convinced (or only strongly believe) that I am wrong,
you have an easier way to proof it: simply solve the configuration
given above (and possibly show me, that resolving those patterns
you displayed above is needed to do so.)

Very thrilling!

Regards,
Gregor



Laura

  



___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Another idea of Conway

2009-09-13 Thread Gregor Lingl

Although my posting to this list seems to tend to become
a somewhat autistic activity I'd like to reveal the 'mystery'
behind the script below:

http://esolangs.org/wiki/Fractran
http://en.wikipedia.org/wiki/FRACTRAN

Would writing a fractran interpreter in python be an interesting
project for teaching CS? (My first try below allows for a lot of
optimizations, e.g. not to use Fraction but resort to (long) ints.)

Best wishes,
Gregor

Gregor Lingl schrieb:

Hi all,

on vacation in the Tyrolean Alps one evening
I've found the time to implement another (I assume
less well known) idea of John Conway.

Just for fun.

from fractions import Fraction

fracs = [Fraction(f) for f in
 "17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11 
15/14 15/2 55/1".split()]


def fracgame():
   z = Fraction(2,1)
   while True:
   for f in fracs:
   n = z * f
   if n.denominator == 1:
   break
   yield int(n)
   z = n

def pow2(z):
   n = 0
   while z % 2 == 0:
   n += 1
   z //= 2
   return (z == 1) * n
  def what():
   fg = fracgame()
   while True:
   z = next(fg)
   n = pow2(z)
   if n != 0:
   yield n

what = what()
print(next(what))
print(next(what))

# the following will take 1 or 2 minutes

##w = 0 ##while w < 100:
##w = next(what)
##print(w)

Comments or discussion may follow when
I'm back to Vienna.

All the best,
Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] casino math (unit three) (Saturday night fever)

2009-09-12 Thread Gregor Lingl



Laura Creighton schrieb:

In a message of Wed, 02 Sep 2009 03:29:36 +0200, Gregor Lingl writes:
  

Laura Creighton schrieb:



I think that the pysol game 'Pile On' is always solvable.
Anybody know for sure?  Writing a program that exhaustively creates
all the possible layouts and then solves them seems possible, 
  

...

But then, I wasn't really looking for the brute-force proof, but the
elegant one.  I was hoping for an induction proof for 4 sets of 4
cards, n cards, and n + 1 cards, but so far I haven't managed it.
  

Hi all,

1) this approach reminds me of Paul Halmos' saying:

Computers are important, but not to mathematics.

2) If this is considered to be true - or at least to be reflecting some 
essential

features of mathematics, I'd understand why the problem is not dicussed more
deeply on this list. On the other hand this is a real life *casino math* 
problem,

at least for solitaire lovers.

What would your answer or advice be if some of your students asked you
how to treat this problem?

3) I, for my part, felt uneasy with the fact, that the problem was set,  
but not treated at all.
In a previous posting I had supposed, that Laura's proposition might be 
false.
I consider it very unsatisfying to have a proposition, which to treat 
seems not

to be far beyond my abilities and not to know the *truth*

My approach was like this:

I  wrote a little backtracking script that solves Pile On configurations 
and I
found some unsolvable ones. But I did (and do) not know if the script is 
correct -

which means, that I do not have a proof of its correctness. But I used it to
create a small collection of unsolvable  Pile On layouts, wrote some 
tiny utilities

and tried to find some patterns in the unsolvable configurations.

Finally I created a configuration by hand - wou will immediately see 
below that
this is not a random configuration - and I think I have a proof of its 
unsolvability.


Configuration:

 (   (11,  6,  2,  1),
 (11, 10,  4,  1),
 ( 9,  2,  6,  3),
 ( 9,  4,  8,  3),
 ( 7, 12, 10,  5),
 ( 7, 12,  2,  5),
 ( 5,  8,  4,  7),
 ( 5,  6, 12,  7),
 ( 3, 10,  8,  9),
 ( 3,  2,  6,  9),
 ( 1,  4, 10, 11),
 ( 1,  8, 12, 11),
 (13, 13, 13, 13),
 (),
 ())

Proof (sketchy):

The investigation of the game-tree takes advantage of the symmetries of 
the configuration.

Odd ranks occur only in the first and the last place of a pile.

You can start to fill the two empty piles essentially in two ways:

(1) - Put two cards with equal odd ranks on pile 14  (e. g.: 1, 1)
   - put one of the freed cards with even ranks on pile 15  (e. g.: 2)
 Now pile 14 is locked and the also the piles you have taken the 
odd cards from. (in my example piles 1 + 2) 
 These now have even topmost cards ( 6 and 4) but those also do not 
match,
 because the four even ranked cards belonging to those piles have 
different ranks.


(2) - Put two cards with equal odd ranks on pile 14  (e. g.: 3, 3)
   - Put two more cards with equal odd ranks on pile 15  (e. g.: 11, 11)
   - Now you have freed four even ranked  cards. If these are pairwise 
different, you are done:

 everything is blocked, that means no solution on this path.
   Remark: there are only 15 pairs of pile-pairs like ((3,3), (11,11))

(3) Now you have to investigate those situations, that arise from doing 
the (2)-procedure but
   do not result in four different even cards on top of the piles. 
These belong to the following pairs

   of piles (named after their topmost odd rank):

   (1,5), (1,7), (3,9), (5,11), (7, 11)

   Most of them can be completed very quickly similar to (1,5) as example:

   11, 6, 2
   11,10, 4
   ..
7,12,10
7,12, 2

   by putting one of the twos on top of the other and everything is 
blocked again.


   Only one sitiatuaton leads to a branch which has a few more 
branching steps: (5, 11)


   7, 12, 10
   7, 12,  2
   ...
   1, 4, 10
   1, 8, 12

   Putting first 10 on second one and first 12 upon last 12 frees 7. 
Now for the first
   and only time you can use two more piles with 7 as topmost cards but 
that also blocks

   immediately.

   This is the only case, which uses one of the odd ranked cards in the 
first column.


Should I now consider the problem as solved? I tend to:

  
Proposition: ...


pysol game 'Pile On' is *not* always solvable.


Of course I might have overlooked something and my proof is incomplete. I'd be 
very
glad to have someone checked it. Moreover there might be configurations, that 
have
an even smaller game tree.

...

Are you convinced now, that the proposition ist true?
Or do you know that it is false?
Perhaps you don't care if its true or false?

Can you do something with this as a teacher of mathematics?
Or as a teacher of computer science?
And what if you were an employee of a casino

Re: [Edu-sig] casino math (unit three)

2009-09-02 Thread Gregor Lingl

Laura Creighton schrieb:

In a message of Wed, 02 Sep 2009 03:29:36 +0200, Gregor Lingl writes:
  

Laura Creighton schrieb:


In a message of Mon, 31 Aug 2009 22:23:55 PDT, kirby urner writes:



  
  

On break, we encourage playing with Pysol maybe...

http://www.pysol.org/
http://pysolfc.sourceforge.net/
http://tktable.sourceforge.net/tile/
http://pygames.sourceforge.net/

Kirby
4D



I think that the pysol game 'Pile On' is always solvable.
Anybody know for sure?  Writing a program that exhaustively creates
all the possible layouts and then solves them seems possible, 
  


  

Hi Laura,
I fear that this is not  practicable.  There are 52! =
80658175170943878571660636856403766975289505440883277824
permutations of 52 cards. If one considers the permutations of the 13 pil
es
as equivalent and also the permutations of the four suits one still 
arrives at a number
of possible Pile On games that exceeds by far the number of nanoseconds 
that passed

since the beginning of the universe.



I don't think that it is quite as bad as all that, given that all we
really have is a set of 52 cards which are 4 sets of 13 cards with
different marks on them.  Thus there is a significant reduction you
can make at the start because an initial set where all the 8s are
swapped for all the 4s are equivalent.
  

Yes, you are certainly right. Nevertheless, if I take 52!,
- divide it by (4!)**13 accounting for the not-distinguishability of the 
four sorts of a suit
- divide this by 13! accounting for the interchangability of the ranks 
(your suggestion)

- divide this by 13! accounting for the permutations of the 13 piles
I arrive at 2373239768247142364082899540328 which is still
approx. 3.7 e+12 times the age of the universe in seconds.

May be there are still more symmetries to be considered. For me 
combinatorics

is an unstable ground :-(


But then, I wasn't really looking for the brute-force proof, but the
elegant one.  I was hoping for an induction proof for 4 sets of 4
cards, n cards, and n + 1 cards, but so far I haven't managed it.

  
Yes, I understood. An elegant mathematical proof for this would be 
interesting. I'd like

to see one. But what if the conjecture is wrong?

My ugly little backtracking program could not solve the following 
configuration:

(
(8, 4, 10, 4),
(9, 3, 2, 10),
(11, 6, 3, 9),
(8, 7, 1, 13),
(6, 8, 7, 12),
(5, 9, 12, 1),
(13, 3, 2, 1),
(13, 4, 6, 3),
(12, 6, 7, 7),
(11, 4, 10, 9),
(12, 5, 11, 11),
(2, 1, 5, 13),
(5, 8, 2, 10),
(),
()
)

Although out of of a series of 100 randomly generated start situations 
this is the
only one it could not solve, I fear chances are much higher, that my 
program has a bug
than that this is indeed not solvable. However I'd be very glad to see a 
solution for this

configuration. (Do you have a deck of cardes at hand?)

I for my part cannot check this, because there are many configurations I 
cannot solve
by hand that *are* solvable by my script. So, if I cannot mange it, that 
means nothing.


(Indeed originally I started to write this script because I tought
it might find a counterexample).

Best wishes (for finding the proof, and more)

Gregor


Yes, I would also be interested in such a proof. I for my part learned 
to know Pile On
only today and I find it rather difficult to play. So from my own very 
irrelevant
experience would expect that there are start configurations which might 
not be solvable -

--- at least for me :-(



Don't believe the strategy that pysol gives about not stacking 3 cards
of a same rank on a single.  As far as I can tell that is nonsense.  But
do keep track of what cards are on the bottom.

  

Thanks for the deverting hint
Gregor



You are most welcome. :-)

Laura


  


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] casino math (unit three)

2009-09-01 Thread Gregor Lingl

Laura Creighton schrieb:

In a message of Mon, 31 Aug 2009 22:23:55 PDT, kirby urner writes:



  

On break, we encourage playing with Pysol maybe...

http://www.pysol.org/
http://pysolfc.sourceforge.net/
http://tktable.sourceforge.net/tile/
http://pygames.sourceforge.net/

Kirby
4D



I think that the pysol game 'Pile On' is always solvable.
Anybody know for sure?  Writing a program that exhaustively creates
all the possible layouts and then solves them seems possible, 

Hi Laura,
I fear that this is not  practicable.  There are 52! =
80658175170943878571660636856403766975289505440883277824
permutations of 52 cards. If one considers the permutations of the 13 piles
as equivalent and also the permutations of the four suits one still 
arrives at a number
of possible Pile On games that exceeds by far the number of nanoseconds 
that passed

since the beginning of the universe.

but
I keep thinking there has to be a more elegant proof in there.
  
Yes, I would also be interested in such a proof. I for my part learned 
to know Pile On
only today and I find it rather difficult to play. So from my own very 
irrelevant
experience would expect that there are start configurations which might 
not be solvable -

--- at least for me :-(

Thanks for the deverting hint
Gregor

P.S.: According to your suggestion I wrote an ugly little program, that 
up to now

was able to solve all the sample start configurations I fed it with. ;-)


rules here for those unfamiliar with the game (googling for 'Pile
On' seems to generate a myriad of false positives).

Pile On
One-Deck game type. 1 deck. No redeal.

Begin:
The game begins with 13 piles of 4 cards, ina random order, plus 2 empty piles.

Goal:
Rearrange the cards so that each pile contains four cards with the same rank.

Rules:

Cards can be moved on top of any other card or cards of the same rank,
or to empty piles.  Groups of cards can be moved if they are of the
same rank.

A pile cannot have more than four cards, and an empty slot can be
filled with any card or group of cards with the same rank.

___

So, simple.  But always solvable?  I am not sure about that.

Laura
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

  


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] Another idea of Conway

2009-08-31 Thread Gregor Lingl

Hi all,

on vacation in the Tyrolean Alps one evening
I've found the time to implement another (I assume
less well known) idea of John Conway.

Just for fun.

from fractions import Fraction

fracs = [Fraction(f) for f in
 "17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11 
15/14 15/2 55/1".split()]


def fracgame():
   z = Fraction(2,1)
   while True:
   for f in fracs:
   n = z * f
   if n.denominator == 1:
   break
   yield int(n)
   z = n

def pow2(z):
   n = 0
   while z % 2 == 0:
   n += 1
   z //= 2
   return (z == 1) * n
  
def what():

   fg = fracgame()
   while True:
   z = next(fg)
   n = pow2(z)
   if n != 0:
   yield n

what = what()
print(next(what))
print(next(what))

# the following will take 1 or 2 minutes

##w = 0 
##while w < 100:

##w = next(what)
##print(w)

Comments or discussion may follow when
I'm back to Vienna.

All the best,
Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] some notes...((partly) OT)

2009-08-25 Thread Gregor Lingl



kirby urner schrieb:

Been sharing some Python lore with Wittgenstein fans (obscure,
esoteric philosopher of 1900s vintage).

  

Hi Kirby, again,

as someone interested in architecture (hopefully not only of Buckminster 
Fuller) following the link of my previous post you might have noticed, 
that Ludwig Wittgenstein from 1926 to 1928 was heavily involved in 
building the so called Wittgenstein house or Stonborough House (together 
with Paul Engelmann, a friendly architect), one of the most modernist 
buildings in Vienna then.See e. g.:  
http://www.spiluttini.com/nextroom.php?id=1681  Incidentally it is 
located in Vienna's third district, the one where I live. So if you 
intend to visit Vienna somewhen - which is rewarding anyway - I'll be 
glad to show it (and some other interesting places) to you.


And now to something completely different: one can find quite a few 
connections between Python and Wittgenstein, for example (don't be 
surprised):


http://mail.python.org/pipermail/edu-sig/2000-July/000592.html
http://mail.python.org/pipermail/python-list/2003-February/188065.html

and very up-to-date

http://oreilly.com/catalog/9780596516499/

and a lot more, not to forget:

http://www.youtube.com/watch?v=m_WRFJwGsbY

Regards,
Gregor

Kirby
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig
  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] some notes...

2009-08-24 Thread Gregor Lingl

kirby urner schrieb:

Some of what's going on in my neck of the woods:


  



Been sharing some Python lore with Wittgenstein fans (obscure,
esoteric philosopher of 1900s vintage).

  

Hi Kirby,

according to

http://en.wikipedia.org/wiki/Wittgenstein

this seems not to be exactly the right characterization of Wittgenstein.

Best wishes from Vienna,
Gregor


Kirby
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig
  


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] more on digital math...

2009-08-09 Thread Gregor Lingl



kirby urner schrieb:
--...

Two Python specific feedbacks from that meeting:

A.  Another Title

One of the teachers is using this book, which was assigned to him (he
didn't choose it):

Python Programming in Context by Miller and Ranum:
http://www.flickr.com/photos/17157...@n00/3800868585/
http://www.amazon.com/Python-Programming-Context-Bradley-Miller/dp/0763746029/
  

...

There's a lot of turtle stuff in the above title, but I'm not sure to
what extent, if any, it works of Gregor's version.
  
Programming in Context uses cturtle, a slightly augmented version of an 
early version of my xturtle module. The additions proposed by Brad 
Miller have found their way into turtle.py. So turtle.py has definitely 
the full functionality needed in the book.


However there have been made some changes in the naming of certain 
functions/methods in order that turtle.py complies with the naming 
conventions for modules of the standard library, e. g. onClick -> 
onclick and things like this.


Anyway it should not only be possible but also  very  easy to adapt the 
programs of the book to run with turtle.py


The book has an appendix with a description of the API of cturtle, which 
can easily compared with Python's docs for the turtle module to find out 
which are the differences.


Regards,
Gregor


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Pycon organizers is now talking about poster sessions

2009-07-31 Thread Gregor Lingl



Laura Creighton schrieb:

I think it would help if an actual teacher got involved before they
decide what teachers want without consultation ...

Laura

  

Hmmm, don't know what to do with this. Seems to be a reply to some posting.
Ok, I'm a teacher, but I definitely do not belong to the circle of 
pycon-organizers ...


I think it would be helpful if you posted the original to EduSig?

Best wishes,
Gregor

ps -- unfortunately you have to subscribe to read the archive.  I have
no idea why.  http://mail.python.org/mailman/listinfo/pycon-organizers
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] turtle in education

2009-07-31 Thread Gregor Lingl

Hi Roberto, hi all,

I've just created a repository of turtle graphics demos/applications
at google code:

http://code.google.com/p/python-turtle-demo/

There are two versions of the collection: one for use with Python 3.1
and one for use with Python 2.5 / 2.6. The latter contains a backport
of version 1.1 of the turtle module (from Python 3.1) to Python 2.

Among others it contains all the examples I have demonstrated
at Pycon 2009 and at Europython 2009.

If you are interested to amend some of these examples, add some
explanatory material or contribute additional examples, please tell
me so I could add you as a committer to the project.

Maybe this repository could evolve to something Roberto was
asking for (below).

If you have questions concerning the examples, feel free to ask here.

I hope that this collection will prove to be useful.

Best regards,
Gregor


roberto schrieb:

hello,
i am looking for materials, experiences etc. about using turtle module
in math, physics and related for middle or high school students

i realized a lot of work is going on but is there any place where all
or part of this material is gathered ?
i am going through the talk of Gregor Lingl at PyCon;

if you're aware of anything else just tell me

thank you very much
  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Bernoulli Numbers (a generator)

2009-07-15 Thread Gregor Lingl

Very interesting issue, superbly documented by Kirby, thanks!

May I contribute a slightly streamlined version of the seidel-generator:
see attachment. (Please check if everything is correct.)

Regards,
Gregor


kirby urner schrieb:

Just adding to what's on file, not sure this is a "must have" but it's
fun to do, especially given the association of Bernoulli Numbers with
"the first computer program" as scoped out in Ada's notes:

http://www.flickr.com/photos/17157...@n00/3718903352/sizes/o/  (shell
view, Akbar font)

http://www.4dsolutions.net/ocn/python/ada.py   (source code)

According to Wikipedia, this is similar to what Knuth recommends i.e.
we're staying with integer operations, although I'm using the Fraction
type to output results (Bernoulli numbers are fractions with lots of
digits once you get into 'em, ideal grist for the mill when learning
about Python generators).

Kirby
4D

  
"""
Python version: 3.1
author: Kirby Urner, 4D Solutions
release: 1.01, July 15, 2009

quick and dirty implementation of Bernoulli numbers
as a generator, getting clues from Wikipedia article

code of seidel generator slightly streamlined by Gregor Lingl


Dedication:
"to Ada Byron, with respect and admiration"

(hence name ada.py)

"In note G of Ada Lovelace's notes on the
Analytical engine from 1842, Lovelace
describes an algorithm for generating
Bernoulli numbers with Babbage's machine [~ 1].
As a result, the Bernoulli numbers have
the distinction of being the subject of
the first computer program."
Wikipedia:  http://en.wikipedia.org/wiki/Bernoulli_number

Source code (current version):
http://www.4dsolutions.net/ocn/python/ada.py

"""

from fractions import Fraction

def seidel():
"""
"...in 1877 Philipp Ludwig von Seidel published an ingenious
algorithm which makes it extremely simple to calculate Tn."
(Ibid, Wikipedia)

See OEIS:
http://www.research.att.com/~njas/sequences/A000111
"""
yield 1
yield 1
row = [1]
while True:
t = 0
newrow = []
for i in row:
t += i
newrow.append(t)
newrow.append(t)
yield t
row = reversed(newrow)

def bernoulli():
yield Fraction(1,1)
yield Fraction(-1,2)
seidelgen = seidel()
next(seidelgen)
sign = 1
n = 2
while True:
sign *= -1
denom = 2**n -4**n
numer = sign * n * next(seidelgen)
next(seidelgen)
n += 2
yield Fraction(numer, denom)
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] PDF geometry animations (ReportLab?) - and turtle module

2009-05-17 Thread Gregor Lingl



kirby urner schrieb:

On Sun, May 17, 2009 at 9:06 AM, Edward Cherlin  wrote:
  

On Sun, May 17, 2009 at 6:35 AM, Gregor Lingl  wrote:


kirby urner schrieb
  



Brilliant work Gregor, ran yours just now (I have 2.5, 2.6 and 3.0 all
installed on Ubuntu Dell Jackalope laptop, WinXP KTU3 lagging in its
number of Pythons).

Happy birthday to me! (literally -- turning 51 today)
  

Yeah, happy birthday to you. Hope you are celabrating it instead of reading
this mail just now.

I think Ron will be quite pleased with such a quick turnaround, and
such a faithful reproduction, right down to the colors.
  

Danke für die Blumen, as we say in German.

If we have a "sea turtles" model, then maybe they'll render his
"rotating egg" flipbook as well, the topic of the half-gig one I
downloaded @ Linus Pauling House yesterday, my CSO present in case
anyone thought they could steal this IP (half joking, Glenn was there
just to hang out and talk about stuff).

Having this uber-teacher in Vienna managing Python's turtle assets is
one of the best developments lately, liked your Blip .tv and sharing a
BOF etc.  Glad we could finally overlap in person a little (Pycons are
great for that).

  

Maybe there will be another opportunity.

I'm going to give another talk on the turtle module at Europython in 
Birmingham

and also a tutorial if there will be at least seven (or so) attendees.

Laura was (and I hope will be) supporting me very strongly.

My ambition is to make the turtle module more popular, as I'm convinced 
that is

easy to use and very versatile as well as powerful.

I've done a few bug-fixes and a few new features for Python 3.1 an it is 
gone
into the (one and only) beta already. You can read about them at the end 
of the

docs

http://docs.python.org/dev/py3k/library/turtle.html#changes-since-python-3-0

You can download the new version separately here:

http://svn.python.org/view/python/branches/py3k/Lib/turtle.py?view=log

And there are two new examples in the demo directory. One of them is
the nim game (I showed it at pycon during the open space). The other one
--  tdemo_round_dance.py  --  is new, needs the new version and is really
nice to view.

You'll find them here:

http://svn.python.org/view/python/branches/py3k/Demo/turtle/

Have a nice party!!

Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] PDF geometry animations (ReportLab?) - and turtle module

2009-05-17 Thread Gregor Lingl

kirby urner schrieb

For those of you looking for a way cool use of Python's ReportLab, I
so far have permission to release this one example "PDF flipbook"
showing how geometry concepts might be communicated using this simple
animation technique:

http://www.4dsolutions.net/presentations/pdf_animation_by_ron_resch.pdf
  
Very impressive and instructive! Is there a description somewhere, how 
'flipbooks' like these

can be produced?

With me this way of communicating geometry concepts worked rather well, 
as you can see in the

attachment.

Regards,
Gregor

I've been sharing this as a teaser with Software Association of Oregon
as well, knowing Ron has a lot more where that came from (I'm suppose
to download a half-gig PDF next time in Pauling House for a bored er
board meeting).

Kirby

  
# uses turtle module from Python 2.6
# hint from Kirby, 15. 5. 09
# http://www.4dsolutions.net/presentations/pdf_animation_by_ron_resch.pdf

from turtle import Turtle, Screen, Vec2D, mainloop
import math

A = 50.  # adjust this to your needs

SHS = A / 20
SF = 1.0
DSF = 1.0038582416
e = Vec2D(3**.5/2, 0.5)

def dsin(angle):
return math.sin(angle*math.pi/180)

def lines(l):
for i in range(6):
d.fd(l)
d.bk(l)
d.left(60)   

class TriTurtle(Turtle):
def __init__(self, c, r, tritype):
Turtle.__init__(self, shape="triangle")
self.c = c
self.r = r
self.speed(0)
self.pencolor(0,0,0)
if tritype == 1:
self.basecolor = (1.0, 0.80392, 0.0)
self.f = -1
self.left(30)
else:
self.basecolor = (0.43137, 0.43137, 1.0)
self.f = 1
self.left(90)
self.fillcolor(self.basecolor)
self.pu()
self.goto(c*A, r*A*3**.5/3)
self.shapesize(SHS, SHS, 1)
self.D = self.distance(0,0)
self.e = (1/self.D)*self.pos()
def setturn(self, phi):
self.goto(SF*self.D*dsin(90-phi)*self.e)
self.settiltangle(phi*self.f)
self.shapesize(SHS*SF)
if abs(self.c) + abs(self.r) > 2:
self.fillcolor([x + (1-x)*phi/360 for x in self.basecolor])
bc = phi/360.
self.pencolor(bc, bc, bc)


s = Screen()
s.reset()
s.tracer(0)
d = Turtle(visible=False)
lines(500)

triangles = []
for c in range(-5,6,2):
triangles.append(TriTurtle(c, 1, 1))
triangles.append(TriTurtle(c, -1, 2))
for c in range(-4,5,2):
triangles.append(TriTurtle(c, 2, 2))
triangles.append(TriTurtle(c, -2, 1))
triangles.append(TriTurtle(c, -4, 2))
triangles.append(TriTurtle(c, 4, 1))
for c in range(-3,4,2):
triangles.append(TriTurtle(c, 5, 2))
triangles.append(TriTurtle(c, -5, 1))
triangles.append(TriTurtle(c, -7, 2))
triangles.append(TriTurtle(c, 7, 1))
for c in range(-2,3,2):
triangles.append(TriTurtle(c, 8, 2))
triangles.append(TriTurtle(c, -8, 1))
s.tracer(1)
 
for phi in range(1,361):
SF = SF*DSF
s.tracer(0)
for t in triangles:
t.setturn(phi)
s.tracer(1)

mainloop()
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] What version of Python to teach ....

2009-04-19 Thread Gregor Lingl

Edward Cherlin schrieb:

On Sun, Apr 19, 2009 at 12:07 PM, Laura Creighton  wrote:

One note:
It is very important to teach your students how to read code.  ...

...


It would be interesting to go through this collection of examples
used in teaching 2.x, and find out how much of the new code just
works, and what are the remaining issues
It's certainly not the only issue, if code 'just works' or not. There 
are quite a few
differences between Python 2 and Python 3 that concern the semantics of 
code.


As a very elementary example consider the different meaning of

range(5)

in Python 2/3. Imho in this case at first it would be important to find
didactically clean ways  to explain  new concepts like these  to beginners.
Of course I know that these  concepts are not entirely new, but with
Python 3 they need to appear at a much  earlier  stage, e. g. when
introducing the for loop.

In 'former times' we could say: range(5) is a list (i. e. a container or 
a compound
data type) and the for loop does things for every element in this list. 
And you could view

this list:


range(5)

[0, 1, 2, 3, 4]

for item in range(5):

  print item

 
0

1
2
3
4

type(range(5))



... easily to grasp

Now, with Python 3,  we have:


range(5)

range(0, 5)

for item in range(5):

  print(item)

 
0

1
2
3
4

type(range(5))



How do you explain the nature of range to beginners? (Not a a rhetorical
question, I'd really like to know different approaches how to do it!)

At least you can see, that this is a much more important question
than e. g. the parentheses around item (because of print being a
function now  - but even here the semantic difference between a
function and a statement is the point and not the parentheses ...)

Regards,
Gregor



___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] PyCon 2009 - Some photos from our meeting - etc.

2009-04-10 Thread Gregor Lingl

Hi all,
back home after a  very exciting stay in the USA - Chicago, then New York -
here are a few photos from our PyCon 2009 Open Space meeting of the 
Edu-People


http://www.rg16.at/~glingl/pycon2009/

If you like, you can download the originals using urls like

http://www.rg16.at/~glingl/pycon2009/PyCon2009-XX.jpg

XX running from 01 to 14

--

Are there any plans on when and how to change the educators'
presence on python.org

I noted that there is still Timothy Wilson indicated as the
coordinator of the edu-sig page, which - as far as I understand -
isn't true ( True ) any more.

To replace this by Anre Roberge would be a first -
albeit small  - step - or not?

When will the wiki be installed, we talked about?

I'd like to contribute some material on my turtle module,
which is - as it has been - still not present on that page, :-( ,
but  I'd  like to get some advice  on what is expected.

Regards,
Gregor 




___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Why MIT switched from Scheme to Python

2009-03-25 Thread Gregor Lingl



Daniel Ajoy schrieb:

http://www.wisdomandwonder.com/link/2110/why-mit-switched-from-scheme-to-python

Daniel

  
Do you consider this to shed light on the nature and/or qualities of 
Python?

Or of the MIT?
Gregor


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] From trees to text

2009-03-25 Thread Gregor Lingl

Python 2.6
This has a new Python module
It run's also with Python 2.5
You can download it separately from here:

http://svn.python.org/view/python/trunk/Lib/lib-tk/turtle.py?view=log

Docs are here:

http://docs.python.org/dev/library/turtle.html#module-turtle

HTH
Gregor

Edward Cherlin schrieb:

Which Python are you using?

Idle/Python 2.5 say:
Traceback (most recent call last):
  File "", line 1, in 
shape("turtle")
NameError: name 'shape' is not defined

 python orbit1.py
Traceback (most recent call last):
  File "orbit1.py", line 6, in 
speed(0)
  File "/usr/lib/python2.5/lib-tk/turtle.py", line 707, in speed
def speed(speed): return _getpen().speed(speed)
  File "/usr/lib/python2.5/lib-tk/turtle.py", line 588, in speed
"one of %s" % (speed, speeds))
ValueError: 0 is not a valid speed. speed must be one of ['fastest',
'fast', 'normal', 'slow', 'slowest']

  


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] From trees to text

2009-03-25 Thread Gregor Lingl



Edward Cherlin schrieb:

http://tonyforster.blogspot.com/2009/03/orbital-motion-in-python-and-turtleart.html
Orbital motion in Python and TurtleArt
  

I'd like to contribute to this topic just three  scripts using Python's
own turtle module (since 3.6) - for now without any further comment ( as
I'm just preparing my journey to Chicago, leaving Vienna tommorow
in the morning). Of course there are many ways of doing this,
depending on your previous knowledge, approaches to math and physics,
and to programming etc.

Please run the example scripts (and  compare and asses the code,  if you 
like)


# orbit1.py

from turtle import *

shape("turtle")
speed(0)
pu(); goto(200,0); pd()

G = 800
hspeed, vspeed = 0, 1
t = 0
while t < 1000:
   x, y = pos()
   goto(x+hspeed, y+vspeed)
   r = distance(0,0)
   x, y = pos()
   hacc = (-G/r**2)*(x/r)
   vacc = (-G/r**2)*(y/r)
   hspeed = hspeed + hacc
   vspeed = vspeed + vacc
   t = t + 1


# orbit2.py

from turtle import *

color("orange")
dot(10)
color("blue")
shape("turtle")
speed(0)
pu(); goto(200,0); pd()

G = 800
v = Vec2D(0, 1)
t = 0
while t < 1000:
   goto(pos() + v)
   setheading(towards(0,0))
   r = distance(0,0)
   acc = (-G/r**3)*pos()
   v = v + acc
   t = t + 1
  
  
# orbit3.py


from turtle import Screen, Turtle, Vec2D

s = Screen()
sun = Turtle()
sun.shape("circle")
sun.color("orange")

planet = Turtle()
planet.shape("circle")
planet.shapesize(0.4)

planet.pu()
planet.goto(200,0)
planet.pd()

G = 800
v = Vec2D(0, -2)
dt = 0.5

t = 0
while t < 1000:
   planet.goto(planet.pos() + dt*v)
   r = planet.distance(sun)
   acc = (-G/r**3)*planet.pos()
   v = v + dt*acc
   t = t + dt

You can find a more elaborate example using a Planet class here:

http://svn.python.org/view/python/trunk/Demo/turtle/tdemo_planet_and_moon.py?view=markup

Best regards,
Gregor




Intended to demonstrate two things,
a) that programmable simulations are good ways for kids to learn
physics and maths
b) that the programmable block provides a way for kids to move from
simple drag and drop programming to more complicated text based
programming

Tony's point is that the programmable block allows users to explore
Python at any level they like, from a single function call up. This
will be an essential part of my strategy for teaching CS and
programming through Turtle Art.

  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] PyCon dinner, meeting

2009-03-22 Thread Gregor Lingl



Andrew Harrington schrieb:

For Pycon I posted dinner/meeting suggesting some time ago at the BoF site
http://us.pycon.org/2009/openspace/EduSig/

I see no responses.  It occurs to me that may be because I did not 
echo it here!
So here is my response: I'd also like to join this dinner. Friday is ok 
for me.

(I'll arrive in Chicago Thursday late in the evening, 23pm,  so Thursday
would be impossible for me).

Regards,
Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] xturtle robocode idea?!

2009-03-16 Thread Gregor Lingl



Jurgis Pralgauskis schrieb:

Hello,

I've been searching around for python analogue of robocode...
http://en.wikipedia.org/wiki/Robocode

I found just some unfinished experiments

but then I thought xturte should be ideal for this:
- supors 2d movement :)
- supports multiple turtles
- has ontimer event as well as onkey
(http://xturtle.rg16.at/code/xtx_games/xtx_spaceship.py)

maybe smb has tried or wants to try to make little framework for this?
  

Hi Jurgis,

I'll look at this in the evening, or at most tomorrow evening.
Now I've to leave  - to go to work.

May I just point out, that xturtle now lives as turtle.py in the
standard library of Python 2.6 / Python 3.0

It also runs with Python 2.5 and with very few modifications
with earlier versions back to 2.2

Best regards,
Gregor

I saw robocode in action ~5 years ago when my friend was teaching java
maybe now it has more features
but then it was enought to gather the prepaired bots' logics (from each student)
and run them locally alltogether...
and it was really fun and involving ;)
bot had information abour the field and coordinates of other bots (and
they flying missles)
and could decide on direction changing or fireing..
that's all :)


  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] project Euler

2009-02-12 Thread Gregor Lingl
Another interesting site of this type, as you will see strongly Python 
biased, is


http://appgallery.appspot.com/about_app?app_id=agphcHBnYWxsZXJ5chMLEgxBcHBsaWNhdGlvbnMYrhQM 


http://www.challenge-you.com/

which is a google app from the google app gallery and - as such - it 
must itself have been written in Python.


Regards,
Gregor



michel paul schrieb:

This is a pretty cool site:  Project Euler .

It's a list of problems that can't be solved using mathematical 
cleverness alone - they require programming.  After you solve a 
problem, you then get access to the list of previous solutions.


The first one - "Add all the natural numbers below one thousand that 
are multiples of 3 or 5." - is just a Python one-liner. 

The second - "Find the sum of all the even-valued terms in the 
Fibonacci sequence which do not exceed four million."


It's fun looking at the previous solutions in all kinds of other 
languages.  Really shows the elegance of Python.


It reminds me somewhat of JavaBat .  There was 
some discussion earlier about doing something similar in Python?


- Michel


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig
  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] another "must have" generator

2009-01-26 Thread Gregor Lingl



kirby urner schrieb:

This is just to get junior experimenting with convergence / divergence
on the complex plane.  c is our variable.

Per this Wikipedia article (fine to project in class, why not, though
"teacher reading from encyclopedia" shouldn't come off as mechanical):

See: http://en.wikipedia.org/wiki/Mandelbrot_set
Also: http://www.4dsolutions.net/ocn/fractals.html

IDLE 3.0a2
  

def mandelbrot(c):


z = 0 + c
while True:
yield z
z = z ** 2 + c


  

May I again add an interesting thing,
this time another indispensable generator,
more exactly: three of them:

def feigenbaum1(c,x):
   while True:
   yield x
   x = c*x*(1-x)


def feigenbaum2(c,x):
   while True:
   yield x
   x = c*x-c*x*x


def feigenbaum3(c,x):
   while True:
   yield x
   x = c*(x-x**2)

  
along with this testing/experimenting function:


def feigenbaumtest(feigenbaum, iterations=80):
   f = feigenbaum(3.93, 0.5)
   for i in range(iterations):
   res = next(f)
   return res

>>> feigenbaumtest(feigenbaum1, 4)
0.24761176565334103
>>> feigenbaumtest(feigenbaum2, 4)
0.24761176565334098
>>> feigenbaumtest(feigenbaum3, 4)
0.24761176565334167
>>> feigenbaumtest(feigenbaum1, 40)
0.43518828176766455
>>> feigenbaumtest(feigenbaum2, 40)
0.43518808407096854
>>> feigenbaumtest(feigenbaum3, 40)
0.43518950764209768
>>> feigenbaumtest(feigenbaum1)
0.70329204370098442
>>> feigenbaumtest(feigenbaum2)
0.8147039925205275
>>> feigenbaumtest(feigenbaum3)
0.66573747868397481
>>>

Certainly something which demonstrates a (by many)
unexpected relation between maths and computer science.

Regards,
Gregor


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Pythonic Math must include...

2009-01-18 Thread Gregor Lingl

This is a corrected version of my previous posting.

(1) According to the complaint of Michel I have inserted *his*
code instead of Kirby's, which ocurred there (for a second time).
(2) According to a suggestion of Andre I've added (towards the end
of the posting) the code form the cookbook, which is ingenious
but not the fastest one.
(3) I've updated the table of the timings.

Regards, Gregor

kirby urner schrieb:

I think you're correct that the sieve best works with a pre-specified
finite domain:   




To continue work in this area one (or at least me) has to have
some criteria to judge the solutions.
Clearly it was advantageous if there was some consensus about
these criteria in the community.



Fortunately, we have hundreds of years of math pedagogy, so in terms
of avoiding quarrels, start with what's already on the books are "must
have" and just render it Pythonically.




There should be some criteria concerning
(a) the choice of problems and themes,
   e.g. to prefer small problems that expose a single idea  -  or 
rather not

...   etc.,
as well as some
(b) code related criteria, like clarity, conciseness, efficiency, 
beauty (!)

etc., ranked according to
their priorities.



This will be up to each professional teacher in whatever walk of life
-- to judge what to include and what to exclude.  Each teacher will
find her or himself in agreement with some, disagreement with others,
over what to include.  Twas ever thus.
  


I think it's not that easy. I'd like to dive a bit into this topic, 
resuming the code examples
given in this thread and adding a few additional ideas. What concerns 
efficiency, I've
measured the time to compute the 9592/9593 primes in the range up to 
10 and (in order to
get some idea how the algorithm scales) also those up to 50 (on my 
machine).


Here is your, Kirby's, code:

def primes():
  sofar = [-1, 2,3] # a running start, -1 proposed by J.H. Conway
  yield sofar[0] # get these out of the way
  yield sofar[1] # the only even prime
  yield sofar[2] # and then 3
  candidate = 5 # we'll increment from here on
  while True: # go forever
  for factor in sofar[1:]: # skip -1 (or don't use it in the first 
place)

  if factor ** 2 > candidate:  # did we pass?
  yield candidate # woo hoo!
  sofar.append(candidate) # keep the gold
  break  # onward!
  if not candidate % factor: # oops, no remainder
  break  # this is a composite
  candidate += 2 # next odd number please

Time:10:  1.71 s50:  42.72 s
-

Michel Paul's code:

def primes():
   p = [-1, 2, 3]
   for x in p: yield x
   def is_prime(n):
   for factor in p[1:]:
   if factor**2 > n: return True
   if n%factor == 0: return False
   multiple = 6
   while True:
   if is_prime(multiple-1): yield multiple-1; p.append(multiple-1)
   if is_prime(multiple+1): yield multiple + 1; p.append(multiple+1)
   multiple += 6


Time:10:  1.58 s50:  32.25 s
-

I've modified this one slightly, with a surprising effect
(I conjecture mainly due to avoiding copying p repeatedly):

def primes():
  yield(-1)
  p = [2, 3]
  for x in p: yield x
  def is_prime(n):
  for factor in p:
  if factor**2 > n: return True
  if n%factor == 0: return False
  multiple = 6
  while True:
  for cand in multiple-1, multiple+1:
  if is_prime(cand):
  yield cand
  p.append(cand)
  multiple += 6

Time:10:  0.14 s50:  1.05 s
-

Scott Daniels code:

def primes():
  for x in -1, 2, 3:
  yield x
  gen = primes().next
  for top in iter(gen, 3):
  pass # skip useless tests (we skip all multiples of 2 or 3)
  factors = []
  # get pump ready for a 5
  check = -1
  limit = 3 * 3 - 2 # How far will 3 work as top prime?
  factors = []
  while True:
  check += 6
  if check >= limit: # move if this pair needs another factor
  top = gen()
  limit = top * top - 2 # limit for both candidates
  factors.append(top)
  for element in check, check + 2:
  for factor in factors:
  if element % factor == 0:
  break
  else:
  yield element

Time:10:  0.07 s50:  0.50 s
-

Compare the above generators to sieve algorithms:

G.L. minimal sieve

def primes(n):
  s = set(range(3,n+1,2))
  for m in range(3, int(n**.5)+1, 2):
  s.difference_update(range(m*m, n+1, 2*m))
  return [2]*(2<=n) + sorted(s)

Time:10:  0.014 s50:  0.11 s
-


G.L.: sieve

def primes(n):
  s = set(range(3,n+1,2))
  if n >= 2: s.add(2)
  m=3
  while m * m < n:
  s.difference_update(range(m*m, n+1, 2*m))
  m += 2
  while m not in s: m += 2
  return sorted(s)

Time:10:  0.012 s50:  0.086 s
-

Apparently sieves are considerably faster at

Re: [Edu-sig] Pythonic Math must include...

2009-01-18 Thread Gregor Lingl



michel paul schrieb:
On Sun, Jan 18, 2009 at 3:31 PM, Gregor Lingl <mailto:gregor.li...@aon.at>> wrote:
 


Michel Paul's code:


def primes():
  sofar = [-1, 2,3] # a running start, -1 proposed by J.H. Conway
  yield sofar[0] # get these out of the way
  yield sofar[1] # the only even prime
  yield sofar[2] # and then 3
  candidate = 5 # we'll increment from here on
  while True: # go forever
  for factor in sofar[1:]: # skip -1 (or don't use it in the
first place)
  if factor ** 2 > candidate:  # did we pass?
  yield candidate # woo hoo!
  sofar.append(candidate) # keep the gold
  break  # onward!
  if not candidate % factor: # oops, no remainder
  break  # this is a composite
  candidate += 2 # next odd number please

Time:10:  1.58 s50:  32.25 s
-


Actually, that's Kirby's code.
This is what I sent:

def primes():
p = [-1, 2, 3]
for x in p: yield x
def is_prime(n):
for factor in p[1:]:
if factor**2 > n: return True
if n%factor == 0: return False
multiple = 6
while True:
if is_prime(multiple-1): yield multiple-1; p.append(multiple-1)
if is_prime(multiple+1): yield multiple + 1; p.append(multiple+1)
multiple += 6

Is this what was tested?  Or what was listed?  Just curious.

Sorry. Of course, you are right. That was a copy and paste - error.
Your code was what was tested and the result of which is listed in
the table. And you can easily recognize, that it was also your code,
that I had modified. (see below)

Next time I'll be more careful

Gregor

 


I've modified this one slightly, with a surprising effect
(I conjecture mainly due to avoiding copying p repeatedly):

def primes():
  yield(-1)
  p = [2, 3]

  for x in p: yield x
  def is_prime(n):
  for factor in p:

  if factor**2 > n: return True
  if n%factor == 0: return False
  multiple = 6
  while True:
  for cand in multiple-1, multiple+1:
  if is_prime(cand):
  yield cand
  p.append(cand)
  multiple += 6

Time:10:  0.14 s50:  1.05 s
-


Yeah, I like the 'for cand in multiple-1, multiple+1'.  I actually did 
do it that way on a previous occasion.  So this is very interesting.


- Michel

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Pythonic Math must include...

2009-01-18 Thread Gregor Lingl

kirby urner schrieb:

I think you're correct that the sieve best works with a pre-specified
finite domain: 
  




To continue work in this area one (or at least me) has to have
some criteria to judge the solutions.
Clearly it was advantageous if there was some consensus about
these criteria in the community.



Fortunately, we have hundreds of years of math pedagogy, so in terms
of avoiding quarrels, start with what's already on the books are "must
have" and just render it Pythonically.




There should be some criteria concerning
(a) the choice of problems and themes,
   e.g. to prefer small problems that expose a single idea  -  or rather not
...   etc.,
as well as some
(b) code related criteria, like clarity, conciseness, efficiency, beauty (!)
etc., ranked according to
their priorities.



This will be up to each professional teacher in whatever walk of life
-- to judge what to include and what to exclude.  Each teacher will
find her or himself in agreement with some, disagreement with others,
over what to include.  Twas ever thus.
  


I think it's not that easy. I'd like to dive a bit into this topic, 
resuming the code examples
given in this thread and adding a few additional ideas. What concerns 
efficiency, I've
measured the time to compute the 9592/9593 primes in the range up to 
10 and (in order to
get some idea how the algorithm scales) also those up to 50 (on my 
machine).


Here is your, Kirby's, code:

def primes():
   sofar = [-1, 2,3] # a running start, -1 proposed by J.H. Conway
   yield sofar[0] # get these out of the way
   yield sofar[1] # the only even prime
   yield sofar[2] # and then 3
   candidate = 5 # we'll increment from here on
   while True: # go forever
   for factor in sofar[1:]: # skip -1 (or don't use it in the first 
place)

   if factor ** 2 > candidate:  # did we pass?
   yield candidate # woo hoo!
   sofar.append(candidate) # keep the gold
   break  # onward!
   if not candidate % factor: # oops, no remainder
   break  # this is a composite
   candidate += 2 # next odd number please

Time:10:  1.71 s50:  42.72 s
-

Michel Paul's code:

def primes():
   sofar = [-1, 2,3] # a running start, -1 proposed by J.H. Conway
   yield sofar[0] # get these out of the way
   yield sofar[1] # the only even prime
   yield sofar[2] # and then 3
   candidate = 5 # we'll increment from here on
   while True: # go forever
   for factor in sofar[1:]: # skip -1 (or don't use it in the first 
place)

   if factor ** 2 > candidate:  # did we pass?
   yield candidate # woo hoo!
   sofar.append(candidate) # keep the gold
   break  # onward!
   if not candidate % factor: # oops, no remainder
   break  # this is a composite
   candidate += 2 # next odd number please

Time:10:  1.58 s50:  32.25 s
-

I've modified this one slightly, with a surprising effect
(I conjecture mainly due to avoiding copying p repeatedly):

def primes():
   yield(-1)
   p = [2, 3]
   for x in p: yield x
   def is_prime(n):
   for factor in p:
   if factor**2 > n: return True
   if n%factor == 0: return False
   multiple = 6
   while True:
   for cand in multiple-1, multiple+1:
   if is_prime(cand):
   yield cand
   p.append(cand)
   multiple += 6

Time:10:  0.14 s50:  1.05 s
-

Scott Daniels code:

def primes():
   for x in -1, 2, 3:
   yield x
   gen = primes().next
   for top in iter(gen, 3):
   pass # skip useless tests (we skip all multiples of 2 or 3)
   factors = []
   # get pump ready for a 5
   check = -1
   limit = 3 * 3 - 2 # How far will 3 work as top prime?
   factors = []
   while True:
   check += 6
   if check >= limit: # move if this pair needs another factor
   top = gen()
   limit = top * top - 2 # limit for both candidates
   factors.append(top)
   for element in check, check + 2:
   for factor in factors:
   if element % factor == 0:
   break
   else:
   yield element

Time:10:  0.07 s50:  0.50 s
-

Compare the above generators to sieve algorithms:

G.L. minimal sieve

def primes(n):
   s = set(range(3,n+1,2))
   for m in range(3, int(n**.5)+1, 2):
   s.difference_update(range(m*m, n+1, 2*m))
   return [2]*(2<=n) + sorted(s)

Time:10:  0.014 s50:  0.11 s
-


G.L.: sieve

def primes(n):
   s = set(range(3,n+1,2))
   if n >= 2: s.add(2)
   m=3
   while m * m < n:
   s.difference_update(range(m*m, n+1, 2*m))
   m += 2
   while m not in s: m += 2
   return sorted(s)

Time:10:  0.012 s50:  0.086 s
-

Apparently sieves are considerably faster at the cost
that the whole sieve has

Re: [Edu-sig] Pythonic Math must include...

2009-01-17 Thread Gregor Lingl



kirby urner schrieb:

Yes thank you I completely agree.  A stash of sieves, plus data mine
this very archive for our earlier work on this topic.

My only suggestion is you include a generator version e.g.:
  
At first this seems an attractive idea, but in my opinion the idea of 
sieves is fairly antagonistic
to that of generators.  A sieve  is used  to eliminate  from a given set 
elements that have
not some desired property, while generators  (ideally) create  objects, 
one at atime,  with
that desired property. Drastically: you cannot sieve at first all even 
numbers from an infinite set or
sequence. For educational purposes I'd prefer examples that display a 
single concept in
a small and simple way. :-*  A prime number generater based on some 
different algorithm of

course may be interesting and useful.

To continue work in this area one (or at least me) has to have some 
criteria to judge the solutions.
Clearly it was advantageous if there was some consensus about these 
criteria in the community.


There should be some criteria concerning
(a) the choice of problems and themes,
e.g. to prefer small problems that expose a single idea  -  or 
rather not ...   etc.,

as well as some
(b) code related criteria, like clarity, conciseness, efficiency, beauty 
(!) etc., ranked according to

their priorities.

Once I had the following idea: there are so many renowned pythonistas in 
the developers
community, many of them also interested to promote Python in the 
educational area (see for
instance the protagonists in Jeffrey Elkners "Introducing Python"). How 
about to ask them
to make a personal donation to the educators and learners: a piece of 
code, 10 to 12 lines
at most, that they individually consider  to  show most convincingly the 
power or the beauty
of programming with Python - or the fun they have with it. Young people 
like role models ;-)


Regrettably I didn't persue that idea further. What do you think of it. 
Ok, the days of the

early pioneers are over, but perhaps it's still worth a try?

Regards,
Gregor




   

Using Python 3:

  

g = Primes()
next(g)


-1
  

next(g)



  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Pythonic Math must include...

2009-01-15 Thread Gregor Lingl

I'd like to suggest, that some sort of sieve could be included,
for instance as a non very fancy example something like

def primes(n):
   s = set(range(3,n+1,2))
   if n >= 2: s.add(2)
   m=3
   while m * m < n:
   s.difference_update(range(m*m, n+1, 2*m))
   m += 2
   while m not in s: m += 2
   return sorted(s)

(as a starting point), or something similar, a bit beautified or
perhaps you know some different more concise solution ...

An even more compact albeit slightly slower version would be:

def primes(n):
   s = set(range(3,n+1,2))
   for m in range(3, int(n**.5)+1, 2):
   s.difference_update(range(m*m, n+1, 2*m))
   return [2]*(2<=n) + sorted(s)

Or something in between.
These are imho nice applications of the set type.

Gregor




kirby urner schrieb:
Yes, note that my Pascal's includes it, with an embedded zip.  Another 
place list comprehension comes up is in our naive definition of 
totatives as:


def totative(n):
return [ t for t in range(1, n) if gcd(t, n) == 1]

i.e. all 0 < t < n such that (t, n) have no factors in common (are 
relatively prime).  Then our totient function is simply the len of 
this list, giving us a quick way to assert (test) Euler's theorem:  b 
** totient(d) % d == 1 where gcd(b,d)==1.  There's an easy enough 
proof in 'Number' by Midhat Gazale, a must have on our syllabus (I'm 
suggesting).


Kirby


On Thu, Jan 15, 2009 at 6:35 AM, michel paul > wrote:


I like this.

I think another 'must include' for math classes would be list
comprehension syntax.  Not an algorithm in itself, but an
important way of thinking.  It's what we try to get them to do
using set notation, but in math classes it seems simply like a
formality for describing domains, nothing more.  In Python, it
DOES stuff.

- Michel

2009/1/14 kirby urner mailto:kirby.ur...@gmail.com>>

Candidates:

"Must include" would be like an intersection of many sets in a
Venn Diagram, where we all gave our favorite movies and a very
few, such as 'Bagdad Cafe' or 'Wendy and Lucy' or... proved
common to us all (no suggesting those'd be -- just personal
favorites).

In this category, three candidates come to mind right away:

Guido's for the gcd:

def gcd(a,b):
while b:
a, b = b, a % b
return a

Then two generics we've all seen many times, generators for
Pascal's Triangle and Fibonacci Sequence respectively:

def pascal():
"""
Pascal's Triangle **
"""
row = [1]
while True:
yield row
row = [ a + b for a, b in zip( [0] + row, row + [0] ) ]

and:

def fibonacci(a=0, b=1):
while True:
yield a
a, b = a + b, a

IDLE 1.2.1 
>>> from first_steps import *

>>> gcd(51, 34)
17
>>> g = pascal()
>>> g.next()
[1]
>>> g.next()
[1, 1]
>>> g.next()
[1, 2, 1]
>>> g.next()
[1, 3, 3, 1]
>>> f = fibonacci()
>>> f.next()
0
>>> f.next()
1
>>> f.next()
1
>>> f.next()
2
>>> f.next()
3
>>> f.next()
5

Check 'em out in kid-friendly Akbar font (derives from Matt
Groening of Simpsons fame):
http://www.wobblymusic.com/groening/akbar.html

http://www.flickr.com/photos/17157...@n00/3197681869/sizes/o/

( feel free to link or embed in your gnu math website )

I'm not claiming these are the only ways to write these.  I do
think it's a feature, not a bug, that I'm eschewing recursion
in all three.  Will get to that later, maybe in Scheme just
like the Scheme folks would prefer (big lambda instead of
little, which latter I saw put to good use at PPUG last night,
well attended (about 30)).

http://mybizmo.blogspot.com/2009/01/ppug-2009113.html

Rationale:

In terms of curriculum, these belong together for a host of
reasons, not just that we want students to use generators to
explore On-Line Encyclopedia of Integer Sequences type
sequences.  Pascal's Triangle actually contains Fibonaccis
along successive diagonals but more important we're laying the
foundation for figurate and polyhedral ball packings ala The
Book of Numbers, Synergetics, other late 20th century
distillations (of math and philosophy respectively). 
Fibonaccis converge to Phi i.e. (1 + math.sqrt(5) )/2.  gcd

will be critical in our relative primality checks, leading up
to Euler's Theorem thence RSA, per the review below (a
literature search from my cube at CubeSpace on Grand Ave):

http://cubespacepdx.com/
   

Re: [Edu-sig] python teacher = mathematics teacher (namespace)

2009-01-12 Thread Gregor Lingl



kirby urner schrieb:

...
If you go back to the start of the Edu-Sig archives, where I do most
of this work, you'll find Tim Peters and Arthur Siegal using a
math-through-programming approach.  

Hi Kirby,

I do strongly sympathize with your approach to this question - alas: in 
contrast

to most of my students (of math), which do not because of the same reason
they do not like to play the piano, even if they like to hear piano playing.

Nevertheless I think, that not only executable notations have to be 
correct but
also the notations of people's names (in pythonista's namespace) - even 
if they

are not alive anymore.

Arthur Siegel was a very vivid and exiting (sometimes excited) opponent
in discussions with you and therefore I'm sure that you will miss him a lot.
He deserves to be cited by his correct name.

I expect to visit chicago too this year and I hope to have the 
opportunity to

meet you there and also to find a tiny place in the ever growing crowd that
will be listening to your presentation.

Regards,
Gregor

P. S.: notwithstanding the overall appropriateness of your comparison there
is perhaps special difference between the world of mathematics and the 
world
of electronic computing. Supposed that proofs of mathematical theorems 
are at

the heart of mathematicians' output, those proofs *have* to be correct.
On the other hand - as far as I was told and what I experienced - there are
very few substantial computer programs which are correct (i. e. bugfree).

Tim cites 'Concrete Mathematics',
Knuth a co-author, and similar to 'The Book of Numbers' in some ways
(what Iverson-Hui take on).  Siegal is doing projective geometry with
Pygeo, which I think you'll still find, c/o his estate.

I work with Ian Benson, a top curriculum writer in the UK, who is very
connected in the Python community.

Although Python itself is open source, a lot of private sector
business do curriculum writing for profit, so some of these efforts
aren't going to feature in academic papers.

http://tizard.stanford.edu/groups/sociality/wiki/d4276/Visiting_Professorship_(Kingston_University).html

I gave a talk to London Knowledge Lab on how I do Python, which you
may be interested in, also my Chicago talk at Pycon last year drew
large crowds, expecting even more this year, plus I have 3 hours this
time [ and blah blah ]

http://www.bfi.org/our_programs/bfi_community/python

http://blog.showmedo.com/2008/07/30/your-pythonic-math-class-of-the-future-chicago-pycon-screencast/

Kirby
"""

So the way I'm thinking of it, we're all math teachers if we teach
Python, a live (executable) math notation (MN) for implementing
logic-numeric solutions to problems.  We've been trained, especially
in the Anglophone tradition, to maintain all these sharp turf lines,
such that we might be computer scientists in some way, but even there,
we're supposed to respect these various record locking schemes based
on degrees and such claptrap.  Mathematics is something removed from
our purview and relegated to some elite that maybe only uses paper and
pencil (or so "they" like to pretend -- many use Mathematica or
MathCad most of the time i.e. live MNs, just as we do).

Now that the concept of "namespace" has reached some maturity, I think
it's easy to explain that namespaces differ in how they use key words
(like "maths") and equating describing Python teaching or programming
in general as mathematics is maybe not university-speak, but
consistency in design is what we're looking for, not necessarily the
approval of Oxbridge dons or whatever gowned authorities.

So, on with the math teaching!

Kirby

PS:  some of you may have wondered about my "Cockfight!" allusion,
saying one of my computers was set aside for that purpose.  It's just
a concept.  I'm not able to write a game as sophisticated as Spore
coming from a tiny office with only a few partners, most of whom have
other day jobs as well.  I clarify this humble truth in my blog this
morning, with a link back to this list.

http://controlroom.blogspot.com/2009/01/cockfight.html
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Programming in High School

2008-12-10 Thread Gregor Lingl



Daniel Ajoy schrieb:

But the criteria of "relevant problems, easily solved with a quickie
program" is tough to meet.  
  

...

And another point is that some problems cannot be solved using algebra or trig. 
I believe this is one:

http://neoparaiso.com/logo/problema-triangulos.html

It asks the student to determine the values of the segments a and b.
This is a nice problem, which could also find an easy solution in 
Python, not only in Logo, of course ;-)

Like the on attached one, for instance.

I'd only like to add a few remarks to the problem discussed in this 
thread - which I also know very well as a high school teacher in Vienna, 
Austria.


(1) One root of the problem seems to be that whatever "relevant problem" 
we pose, there are *a lot* of different adequate tools to approach it in 
these modern times and it is by no means clear that programming is the 
'natural' approach. See for instance


http://www.rg16.at/~glingl/triangle/

for a different solution to Daniel's problem.

(2) To profit from beeing able to program needs continuous practice. So 
as a teacher of a math class you had to convince *all* of your students 
to do it continually.


(3) This - at least here in Austria - seems to be impossible as long as 
programming is not part of the official math curriculum (like for 
instance the appropriate use of a pocket calculator). Even core math is 
not done by *all* students on their own free will, because they enjoy 
it, or they are interested in it, but by some of them often only because 
they *need* it for their gradutation. And I suppose that programming 
will  never be part of the standard curriculum, even if only because 
only a small part of the maths teachers are proficient in programming. 
So they naturally would oppose such a change.


(4) Moreover it seems to me, that even in the area of computer science 
or computer technology the part which is occupied by programming is 
getting smaller. 25 years ago, if you wanted to do some interesting 
things with a computer, you *had* to be able to program, while nowadays 
there are so many interesting things you can do without programming. For 
instance what do you think, which part of the people working in the 
comuter game industry are programmers? I suppose, this trend also 
diminishes the young people's interest in programming (as well as the 
school authorities interest in putting programming into the mainstream 
curricula.)


(5) Despite all of this I'd also like to contribute a problem, I 
stumbled over yersterday, incidentally. It might not be 'relevant' but 
it's also one that most probably couldn't be solved without computers 
and which without doubt has the potential to stimulate the student's 
interest in math as well as computing:


Christian Goldbach (1690-1783), stated several number theoretical 
conjectures, among them the famous Goldbach conjecture, concerning the 
set of even numbers > 2.


An other (similar) one is the following: every odd positive integer 
could be written in the form p + 2*a**2, where p is a prime (or 1, then 
considered a prime) and a >=0 is an integer. Example: 23 = 5 + 2*3**2 
(to use Python notation). Euler checked this conjecture for odd numbers 
up to 2500 and he didn't find a counter example. Only a century later 
two counter examples were found in the range below 1.  What are 
these two numbers?
The curious thing is, that to this day these two numbers remain the only 
ones found.


Regards

Gregor





Daniel

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


  
# Daniel Ajoys triangle problem
# from Edusig, 10. 12. 2008

from turtle import *

def triangle(wx):
penup(); home(); pendown()
forward(130)
left(180-38)
forward(wx)
setheading(180 + towards(0,0))
forward(70)
right(180-101)
forward(88)
#stamp()
return ycor()

setup(500,250)
mode("world")
reset()
fd(250)

triangle(80)
triangle(50)

# no-frills graphical solution
# of course one could play around with colors etc...

wx1 = 80
wx2 = 50

epsilon = 0.1

while True:
wx = (wx1 + wx2)/2.0
y = triangle(wx)
if abs(y) < epsilon:
print "Solution:", wx
break
if y > 0:
wx1 = wx
else:
wx2 = wx


setworldcoordinates(190, -2.5, 200, 2.5)
write(str(pos())+" for wx = " + str(wx))




___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] school physics/math courses

2008-10-19 Thread Gregor Lingl



roberto schrieb:

hello
(i am rather new in python ...)

i am about to start a course of physics and math for students aged
14-17 (high school)
and i am deeply interested in the possibilty of teaching fundamental
concepts of these subjects via teaching programming;
i chose python (i won't change my mind ...)

so i am looking for resources on how to deal with these topics via
this great programming language;

  

Hi Roberto,

I've done a few short scripts which might be interesting to you. Take
them as examples, which you may use, modify or simply take for
inspiration to do something similar.

The first one, together with an example - tdemo_planet_and_moon.py -
which you might find here:

http://svn.python.org/view/python/trunk/Demo/turtle/

are simulations of gravitational three-body-systems.

tdemo_sierpinsky.py is a script which draws a colorful sierpinsky-triangle
and uses a simple 3D-Vector class. (BTW the gravitation-scripts above use
a 2DVector class which is included in the turtle module.)

tdemo_spaceship.py is sort of a game which I've used in my physics classes
to let my students experience how to drive a spaceship in agravic space. 
(Try
to drive it along a circlular orbit!) Before this, my students in a 
computer science
class had programmed it, so it's code might be worth to be polished a 
bit ;-)


Another mathematically interesting example is the script tdemo_chaos.py 
which
you can also find at the link mentioned above. It shows that the result 
of some

80 iterations of an algebraic expression depends extremely on the way it is
realized in python (that means of the order of arithmetic operations).

All those examples use the turtle module which is part of the Python 
standard

library since Python 2.6. This module is devised to provide very easy
access to graphics which might be of importance if you do mathematics and
physics, because it allows to avoid some 'bureaucratic' overhead which is
necessary to use Toolkits like Tkinter and others. Thus you can concentrate
more easily on the mathematical and physical contents of you curriculum.

Maybe it might be useful to create some sort of repository in the web
for small classroom dedicated math- and physics related Python scripts?

Regards,
Gregor







i need some help from you and moreover if you are aware of books
already covering these need

thank you in advance
  
#!/usr/bin/python
"""   turtle-example-suite:

tdemo_planets.py

Gravitational system simulation using the
approximation method from Feynman-lectures,
p.9-8, using turtlegraphics.

Example: heavy central body, light planet,
very light second planet! This one will be
deflected several times by the gravitational
force exerted by the first planet.

You can hold the movement temporarily by
pressing the left mouse button with mouse
on the scrollbar of the canvas.

"""
from turtle import Vec2D, Shape, Turtle, mainloop
from time import sleep

G = 8   # gravitational constant

class GravSys(object):
def __init__(self):
self.planets = []
self.dt = 0.01
def init(self):
for planet in self.planets:
planet.init()
def start(self):
for i in range(2):
for planet in self.planets:
planet.step()

class Star(Turtle):
def __init__(self, m, x, v, gravSys, shape):
Turtle.__init__(self, shape)
self.resizemode("user")
gravSys.planets.append(self)
self.gravSys = gravSys
self.dt = self.gravSys.dt
self.penup()
self.m = m
self.setpos(x)
self.vel = v
self.pendown()
def init(self):
self.vel = self.vel + 0.5*self.dt*self.acc()
def acc(self):
a = Vec2D(0,0)
for planet in self.gravSys.planets:
if planet != self:
r = planet.pos()-self.pos()
a += (G*planet.m/abs(r)**3)*r
return a
def step(self):
self.setpos(self.pos() + self.dt*self.vel)
if self != sun:
self.setheading(self.towards(sun))
self.vel = self.vel + self.dt*self.acc()

## create compound yellow/blue turtleshape for planets
## yellow semicircle will always point towards the sun
def createPlanetShape():
s = Turtle()
s.tracer(0,0)
s.ht()
s.pu()
s.fd(6)
s.lt(90)
s.begin_poly()
s.circle(6, 180)
s.end_poly()
m1 = s.get_poly()
s.begin_poly()
s.circle(6,180)
s.end_poly()
m2 = s.get_poly()

planetshape = Shape("compound")
planetshape.addcomponent(m1,"orange")
planetshape.addcomponent(m2,"blue")
s.getscreen().addshape("planet", planetshape)
s.tracer(1,0)
s.ht()

def main():
global sun
createPlanetShape()
## setup gravitational system
gs = GravSys()
sun = Star(100, Vec2D(0,0), Vec2D(0,-3.5), gs, "circle")
sun.color("yellow")
sun.turtlesize(1.8)
sun.pu()
earth = Star(1, Vec2D(100,0), Vec2D(0,350), gs, "planet")
earth.p

[Edu-sig] Edu-Sig web page on www.python.org

2008-10-10 Thread Gregor Lingl

Hi all,

does anybody know who is currently maintaing the Edu-Sig related
web page on www.python.org?

http://www.python.org/community/sigs/current/edu-sig/

I'd just like to suggest to the maintainer, that turtle.py, which now
(i. e. since Python 2.6) belongs to Python's standard library deserves
to be mentioned there in the list "Of interest of educators."

Best regards,
Gregor


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] CP4E in a third world country

2008-10-07 Thread Gregor Lingl

Hello Miguel,

Python 2.6, which was released one week ago, comes with a new turtle
module. Perhaps this is something, you and your kids would like as it is
pure educational Python software based on Tkinter. One of it's design
goals was to provide easy access to graphics, thus avoiding the need to
tinker around with the administrative overhead to create
Tkinter-canvases and the like. It covers a considerable subset of
MSW-Logo, but has an even nicer animation of the turtles - it's 'drawing
devices', which give a good graphical feedback about the correct working
and also possible bugs of the programmers ideas. Moreover it can be used
in procedural or object oriented programming style.

It can also be used interactively from IDLE, provided you use it with
the -n switch, for "no subprocess".  A link like (for Windows)

C:\Python26\pythonw.exe C:\\Python26\Lib\idlelib\idle.pyw -n

will do it. For instance:


from turtle import *   # imports all the turtle-graphcis functions
forward(100)
left(120)
forward(100)
right(240)
shape("turtle")
fd(100)
lt(840)



Sequences of a few elementary turtle graphics functions can be used to
compose rather eleborate drawings. All the turtle-graphics functions are
also available as turtle-methods, eg.:


from turtle import Turtle
bob = Turtle()
ted = Turtle()
ted.left(180)
bob.color("red")
ted.color("blue")
ted.begin_fill()
for edge in 1,2,3,4:

   for turtle in bob, ted:
   turtle.forward(120)
   turtle.left(90)


ted.end_fill()


(These examples just for whetting your appetite)

Moreover the module has an online-help via docstrings and provides the
possibility to replace the english docstrings with ones that are
translated to another language. (Alas, these do not exist in spanish
yet, but if someone wishes to do the translation I could give some hints
on how to proceed.)

The loading of these foreign-language-help ist configured via a
turtle.cfg file which also allows to configure several other properties
of the module at startup, such as window size, canvas size (with
scrollbars if necessary),  turtle-shapes and even  a  'logo'-mode
which  provides orientation  and  angle-measurement like in MSW-Logo.
The standard configuration is as to ensure  compatibility with the old
turtle module which was part of Python until 2.5

The module has also been ported to Python 3.0 and will be part of that
Python version which will be released presumably at the beginning of
December.

If you want to try out the module with Python 2.5, you can find it here:

http://svn.python.org/view/python/trunk/Lib/lib-tk/turtle.py?rev=66686&view=log

The online-docs (which are included in the distribution as well) you can
find here:

http://docs.python.org/library/turtle.html#module-turtle

A sequence of turtle graphics demo scripts covering a wide range from
easy to rather sophisticated (including a demo-viewer script) you can
find here:

http://svn.python.org/view/python/trunk/Demo/turtle/


If you - or somebody else has any questions I'll be happy to help.

Best regards,
Gregor










___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Network Simulations using Python

2008-09-13 Thread Gregor Lingl



kirby urner schrieb:

Someone should say something about Twisted in this "networking through
Python" thread, but I'm not sure what.
  

I'd just like to point you to Shandy Brown's "Writing Games Tutorial", which
uses Twisted in it's network section:

http://ezide.com/games/writing-games.html

BTW this tutorial also deservers attention because of its explanations on
how to use the MVC pattern with pygame.

Regards,
Gregor



I come at Twisted through Medusa in Zope and readings about asyncore,
think of Twisted somewhat in those terms.

Later I jumped from Zope into Plone, hung out with Alan and those guys
for a sprint in Canada.

At this last OSCON, I hung out with Steve Holden (holdenweb.com) and
Duncan McGreggor (a Twisted guy) most of the time.

Kirby
4dsolutions.net

http://twistedmatrix.com/trac/wiki

http://www.nightmare.com/medusa/

http://docs.python.org/lib/module-asyncore.html

http://plone.org/
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


  

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] after-school python, age 11+

2008-08-20 Thread Gregor Lingl

Jeremy Gray schrieb:

Hi all,

This is my first post to edu-sig, and its sort of long. In a nutshell:
a) I have developed and posted a few new material for kids getting 
started with programming, e.g., for an after-school club, at 
http://afterschoolpython.pbwiki.com/  Its free (no advertising ever, 
open-source recommended), and will be so forever.
b) I am interested in collaborating with or sharing notes with others, 
to make it even better.


Being new to this interesting forum, I'll introduce myself briefly. 
I'm a dad (two kids, age 11 and 5), and have always been a geek at 
heart. I do science for a living (human brain imaging and psychology, 
using computers for everything), and have interests in education 
(including National Science Foundation grants related to education 
research). I'm not an elementary-age educator, although have family 
members who are educators. So it seems inevitable that I'd end up 
lurking on python edu-sig :o) I've seen some fairly long posts, so 
I'll take the plunge with a longish one myself. Apologies if that's 
frowned on.


Basically, I want to teach my 6th grader how to program this coming 
year. We've fooled around with logo / turtle graphics and like it, and 
are ready for a real language.

Hi Jeremy,

I just wanted to point out that Python also has a turtle graphics 
module: turtle.py
While turtle.py in Python 2.5 did a good job, it has somewhat limited 
capabilities. It will be replaced by an enhanced one from Python 2.6 on. 
This enhanced module (fomerly known to some of us as xturtle.py) is 
already part of Python 2.6 beta2 and I'll do a more elaborated posting 
on it as soon as beta3 is out, which should happen these days.


The new turtle module has - as one of it's new features - enhanced 
animation which is intended to serve as a visual feedback facility for 
young programmers. (Moreover they can - if they wish - choose the shape 
for their turtles, for instance they can use turtle-shaped turtles or 
design their own shapes ...)


The new module will also run unaltered - as is - under Python 2.5

You can download it from here:

http://svn.python.org/view/python/trunk/Lib/lib-tk/

The docs can be found here:

http://docs.python.org/dev/library/turtle.html#module-turtle

Regards,
Gregor

I was quickly sold on python as the way to go, despite never having 
used it myself (or any OO language ... or maybe in part because of 
that--I want to learn something too!). I looked around for existing 
materials, and am really impressed by how much is out there for python 
(one of several selling points). yet I did not find anything I was 
that completely happy with. I looked carefully at the following, and 
learned a lot, and like a great many things about them:

- Snake Wrangling for Kids
- LiveWires summer program
- other resources linked on Beginner's Guide to Python for non-programmers
- A byte of python
- J. Miller's 2004 PhD dissertation. his analysis of posts on what the 
community thinks about desirable features in using python in education 
is really helpful. one point that caught my eye was the dearth of 
intro curriculum materials.


So, I took the plunge and have started to write something up myself. 
Its well underway, but is a work in progress, at
http://afterschoolpython.pbwiki.com/ 
My goal is to have it be an experience in learning how a computer can 
enhance your mind, using a real language, aimed at a young audience 
without talking down to them. (Young but able to read, type using a 
text editor, and do some elementary-school math). I tried to follow 
Miller's guidelines on desirable features, but have not followed them 
all (not yet at least, graphics is a glaring example).


The key thing that motivated me to put effort into 
yet-another-free-resource for learning python was to try to focus on 
problem solving as enhanced by a computer, for this age group. Plus 
sneaking in some geek tidbits here and there, like a few linux 
command-line tools (e.g., top), so that they are not seen as exotic or 
weird or hard. A few of the activities are basically cognitive 
science, and a few are more or less math.


I'm posting for two main reasons.
1. The first is just to say:  Hi, there is a little bit more 
curriculum "raw material" out there, I hope someone else can use it 
too. Who might be interested? My guess is that it will be most 
appropriate for a self-selected audience, rather than cp4e. I envision 
it being used in an after-school group (hence the name), probably at 
the middle-school level but maybe some things would work for advanced 
elementary (I'm not an educator, just guessing). Maybe some could be 
rewritten for an older audience.


Some of the activities are tried and true ("hello world!"), and some 
are ones I thought up, like counting to a million to give kids a gut 
sense for how fast computers are, described as turning yourself into a 
cyborg, counting to a million in one second, and then changing back. I 
want kids to see themselves 

Re: [Edu-sig] Kirby from Pycon

2008-03-17 Thread Gregor Lingl


Richard Guenther schrieb:
> Hi Gregor (and Kirby),
>
> I've been silent for a while on this list, as I've been in the process 
> of changing email accounts, installing various Linux distros, and my 
> full-time job
>
> I teach high school students in Colorado, US.  I have downloaded 
> Xturtle and some of my students and I have played with each example.  
> I will show it to my programming club this week. 
>
> I like what I see so far.  I do use the regular turtle module, but 
> most of my students want to leave it behind and switch to pygame after 
> a little while.  Xturtle has some advantages.
>
> The xturtleDemo.py file runs quite well on Ubuntu Linux, except for 
> the moorhuhn game, which uses the winsound module.  I have not tested 
> any of this on Windows, but will do so soon.
Thanks for the feedback, Richard. Perhaps you could create a Linux 
version of moorhuhn game with some (to winsound equivalent module? If 
necessary, from pygame? Do you know the original moorhuhn game? If so, 
you certainly can tell me the original English name of the game. (I 
know, that the English word for Moorhuhn is grouse - but is this the 
name of the game?)

All the best
Gregor

P.S.: Another interesting question is, if Guenther is an English name. 
In fact in German it's frequently used as a first name (as well as Richard).
> Thanks,
>
> Richard Guenther
>
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Kirby from Pycon

2008-03-17 Thread Gregor Lingl


Hi Kirby,
> ...
> I admire and respect your work Gregor, think of you as a generous
> and intelligent guy.  I hope to meet you one day.
>
>   
I certainly would enjoy that.
> ...
>
> The one time I started down the turtle graphics road in my own
> curriculum writing was in connnection with the so-called Lturtle
> or L-system turtle:  http://www.4dsolutions.net/ocn/numeracy3.html
>
>   
My xturtle package 

http://www.rg16.at/~python/xturtle/download.html

contains a demoViewer and a set of 30+ demoscripts, among them two
Lindenmayer examples (of course only twodimensional). One of them 
lets two (different) plants grow in parallel (using generators):

http://www.rg16.at/~python/xturtle/code/xtx_lindenmayer/xtx_twoPlants.py

The other one, more simple, is an example from ethno mathematics.
I'm sure you would enjoy it if you had the time to view it.

Regards,
Gregor
>>  I read your blog entries and regret not to have been there. It was
>>  impossible for me this year, but I consider to manage to attend
>>  PyCon 2009, (if some financial support would be possible from
>>  somewhere ;) ) Let's see.
>>
>>  Looking forward to more from you, later
>>
>>  Gregor
>> 
>
> Likewise,
>
> Kirby
>
>
>   
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Kirby from Pycon

2008-03-16 Thread Gregor Lingl
kirby urner schrieb:
> Greetings from Pycon.
>
> I've mentioned this list to numerous people at this
> conference.  As I said over dinner (hotel buffet),
> I think we have enough talent around this table
> to bring off the revolution (OK, a little short on
> details -- probably why we all seemed to agree).
>
> As we disperse, I encourage those of us already
> here (at the conference and on this list) to keep
> reaching out to the contacts we've made.  Lots
> of cool cosmic fish will slip through our nets if we
> don't (as some will even if we do -- such is life).
>
>   
Hi Kirby,

what do you think about xturtle? Is it cool? Cosmic? A fish ;-)
Will it slip through our nets?

I read your blog entries and regret not to have been there. It was
impossible for me this year, but I consider to manage to attend
PyCon 2009, (if some financial support would be possible from
somewhere ;) ) Let's see.

Looking forward to more from you, later

Gregor

> My two Pycon blog posts (so far):
> http://worldgame.blogspot.com/2008/03/pycon-2008.html
> http://controlroom.blogspot.com/2008/03/more-from-pycon.html
>
> More later,
>
> Kirby
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
>   
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] xturtle - new version

2008-03-14 Thread Gregor Lingl
Hi everyone ...

I've been off line for a while, due to a lot of work ...
... but since approx. two weeks I've found time to continue my work
on xturtle.py and to implement a few hopfully useful features as well
as some example scripts demonstrating them. Only one of them I'd
like to mention here, because it proved really very useful for interactive
work with turtle graphics: an undo() method/function, which serves to
correct painlessly the consequences of wrong ideas ;-) 

Notes on the new features are in a text file in the xturtle package as well
as here:

http://www.rg16.at/~python/xturtle/whatsnew.txt

You can download the zipped package with xturtle.py, a demoviewer
and the sample scripts  from the (still not substantially refreshed) 
website:

http://www.rg16.at/~python/xturtle/download.html

Quite a few users asked and/or encouraged me during the last months
to anew propose xturtle.py as a replacement or a supplement for xturtle.py
either for Python 2.6 and especially for Python 3000. (A port of xturtle.py
to Python3000 is under way and nearly ready!)

Morover there is the following point in PEP-0361, the
Python 2.6 and 3.0 release schedule:

- turtle.py replacement or enhancements

I'll propose my workto the developer community within a short time.
The code of the current version works well,  albeit it certainly still has
some bugs. (I hope to get bug reports form users ) 
I plan to polish the code during the next weeks.

For now I think, that the current version can serve well as a basis for
a discussion about the following topics:

1) about the API - i. e. about the naming of the classes and methods
as well as about the question if there are some which could be eliminated
or other new features which should be added. (Imho I've reached a
point where it seems not to be reasonable to add substantially more 
features)

2) about the question if xturtle should be compatible to turtle.py as far
as possible, in the sense that turtle-programs should run with xturtle
in the same way. (I think this is to a far extent the case now - but it
complicates and extends the code of xturtle considerably.)

Of course many users as well as nonusers of turtle graphics have a
lot of different opinions about it's advantages and disadvantages.I'd
just like to mention once more, the for me it is a very valuable instrument
to visualize computer science concepts easily and consequently to
teach programming. To see better what I mean with this, please have a look
at the code of the minimal_hanoi.py sample script, which implements a
graphical animation of the tower of hanoi game using a lot of advanced
concepts of Python but nearly without any overhead for graphics operations.
That's just my approach to using turtle graphics.

So I'd like to modestly ask you to have a look at the xturtle package,
think about it's usefulness for educational purposes and give some
feedback or contribute otherwise to the discussion.

With kind regards,
Gregor


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] More on graphics with graphics.py (Zelle's)

2007-02-12 Thread Gregor Lingl

kirby urner schrieb:
 
Some of you old timers may recall a project in May, 2004 to implement

Wolfram's minimalist cellular automaton experiments using a Tk canvas
and/or PIL. 
 
As I recall, John showed us how to speed it up a whole lot by passing
some 'False' parameter in the GraphWin call. 
 
However, now that I'm testing the code, in preparation for this post, lo

these many years later (on a faster computer in a different version of
Python (2.5)), and with a newly downloaded graphics.py, I'm seeing
those rows of the Mayan Pyramid, associated with Wolfram's "Rule 30" [1],
run across the screen like some raster beam on an ultra slow TV.

Hi Kirby and all,
I'm not sure if I'm adding something useful or intersting at all, 
because I'm

currently following these threads only very superficially. I just wanted
to demonstrate, that the use of a simple canvas3.py - which uses Tkinter
directly -  can also speed up your ultra slow TV considerably.

See attachments. (nks2.py has only the import statement and the last
line of the next() method  added to nks.py. You can delete the last one
if you don't want to watch the pyramid growing)

Regards,
Gregor Lingl

"""
Used in support of nks.py
by K. Urner
"""

# from Dr. Zelle's graphics library
from Tkinter import Tk
from Tkinter import Canvas as TkCanvas

class Canvas(object):

def __init__(self, width, rows, pixelsize):
self.pixelsize = pixelsize
self.c = Tk()
self.cv = TkCanvas(width=width*pixelsize,
   height=rows*pixelsize,
   background='black')
self.cv.pack()

def drawcell(self, thepoint):
pixelsize=self.pixelsize
therow = thepoint[0]*pixelsize
thecol = thepoint[1]*pixelsize
self.cv.create_rectangle(therow, thecol,
 therow+pixelsize, thecol+pixelsize,
 fill='yellow', outline='yellow')

def showimage(self):
self.c.mainloop() # comment this out if using IDLE with -n switch
pass
"""
by Kirby Urner, 4D Solutions

Version 0.3
Revised: May 10, 2004  9:10 PM -- split into 3 modules, canvas2 uses newer 
graphics.py by Dr. John Zelle
Revised: May  8, 2004  8:00 PM -- changed to rectangles in Tk, other fixes
Revised: May  8, 2004  5:48 PM -- added Tk output (see edu-sig of today)

Usage:
import nks
nks.t1(30,200,100,4)

or

"""

# uncomment one or the other, reload if switching

# from canvas1 import Canvas   # <-- PIL
# from canvas2 import Canvas # <-- graphics.py
from canvas3 import Canvas # <-- Tkinter.py

def base2(n,pad=8):
output = []
while n > 1:
digit = n%2
n //= 2
output.append(str(digit)) 
output.append(str(n))
output.reverse()
return (''.join(output)).zfill(pad)

def makerule(n):
therule = {}
output  = base2(n)
for i in range(8):
therule[base2(7-i,3)] = output[i]
return therule

def sayrule(themap):
for i in range(7,-1,-1): 
thekey = base2(i,3)
print "%s --> %s" % (thekey, themap[thekey])

class Pattern(object):

def __init__(self, n, width=40, rows=20, pixelsize = 1):
self.width = width
self.rule = makerule(n)
self.therow = ('0' * (width//2) +
   '1' +
   '0' * (width - width//2 - 1))
self.rownum = 0
# Canvas imported from either of 2 modules
self.canvas = Canvas(width,rows,pixelsize)

def next(self):
while True:
yield self.therow
for i in range(len(self.therow)):
if self.therow[i]=='1':
self.canvas.drawcell((i,self.rownum))

newrow = ['0'] * len(self.therow)
for i in range(1,len(self.therow)-1):
thekey = (self.therow[i-1] +
  self.therow[i] +
  self.therow[i + 1])
newrow[i] = self.rule[thekey]
self.therow = ''.join(newrow)
self.rownum += 1
self.canvas.c.update()

def showimage(self):
self.canvas.showimage()

def __iter__(self):
return self.next()

def t1(rule, width, height, pixelsize=1):
p = Pattern(rule ,width, height, pixelsize)
g = p.next()
for i in range(width/2):
g.next()
p.showimage()

if __name__ == '__main__':
t1(30,200,100,4)
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] turtle-graphics - Abelson and a sign of the times?

2006-11-19 Thread Gregor Lingl

> Concerning books what I've done is to rely on the old, but very good  
> book, by Abelson and diSessa "Turtle Geometry" (MIT Press) and  
> translate the logo code to Python.

To confront you with a newer (and very interesting) idea of Abelson 
have a look at:

ttp://lambda-the-ultimate.org/node/1840

Regards,
Gregor

P.S.: After having finished the second edition of "Python für Kids"
which was a huge rewrite due to using the new xturtle module
I went on vacation. Back from this I've got to do a lot of work 
which I didn't have time to complete while writing the book.

I just have turned on the edu-sig posting delevery again and 
I hope to be able to enter the turtlegraphics thread soon and
also the development of the xturtle module in the very near
future.






___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] where can I find xturtle?

2006-08-26 Thread Gregor Lingl
There was a server-crash at rg16 while I was
on vacation. That has been fixed now.

You can find xturtle again at

http://ada.rg16.asn-wien.ac.at/~python/xturtle

Sorry for the inconvenience

Gregor
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Python Pedagogy

2006-07-21 Thread Gregor Lingl


Dethe Elza schrieb:

> class Anthro(object):
> 
>  def __init__(my):
>  I = me = my
>  my.self = me
>  my.truism = (phrase for phrase in ['I am', 'that which I am'])
> 
>  def __repr__(my):
>  return my.truism.next()
> 
>  def who(my):
>  I = me = my
>  print me, my.self and I
> 
> if __name__ == '__main__': Anthro().who()
> 

It's really a pity that despite thus much ego-centrism
that poor Anthro couldn't say onother time who his is.

Gregor


> 
> --Dethe
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
> 
> 
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Python Pedagogy

2006-07-21 Thread Gregor Lingl


kirby urner schrieb:
> Although we all agree to use 'self' as the "me object" proxy, it's not
> a keyword, and we could use a different stand in, e.g.:
> 
> class Human (object):
> 
> def __init__(me, name):
> me.name = name
> 
> def __repr__(me):
> return 'Hi, my name is %s' % me.name
> 
  import subgenius
  aguy = Human('Bob')
  aguy
> 'Hi, my name is Bob'
> 
...
> Likewise, I think when coming to think formally in terms of objects
> (vs. informally, which begins with the emergence of language), it
> helps to personally project a "self" into various household objects,
> houses themselves.
> 
...
I find this a very interesting discussion (and was really puzzled by 
Andre's high-level joke in his last posting).

I'd like to supply a paradox counter point of view (perhaps just to
participate in the game). And please forgive me, that I once again use 
my turtles (objects of the Pen-class) in my examples. (They fit into the 
antropomorphic approach, anyway.)

Non - OO, teaching 'the' turtle (logo-slang) to draw a square goes like 
this:

def square(l):
 for i in range(4):
 fd(l)
 lt(90)

As soon as you want to teach to more than one turtle how 'to square'
you have to name them and treat them as objects.

Simple idea:

alex = Pen()
bert = Pen()

def alex_square(l).
 for i in range(4):
 alex.fd(l)
 alex.lt(l)

def bert_square(l).
 for i in range(4):
 bert.fd(l)
 bert.lt(l)

A bit stupid, especially if for instance there comes

chris = Pen()

So why not supply an extra argument to determine, which turtle should
'square':

def square(turtle, l):
 for i in range(4):
 turtle.fd(l)
 turtle.lt(l)

which allow us to say:

square(alex, l)
square(bert, l)

Now a simple trick comes in ...

class Turtle(Pen):
 def square(turtle, l):
 for i in range(4):
 turtle.fd(l)
 turtle.lt(l)

and we immediately better educated turtles

alex = Turtle()
bert = Turtle()
chris =Turtle()

for turtle in alex, bert, chris:
 turtle.square(l)

Hmm..., so - this my paradox 'proposition' - why not use
ClassName.lower() as replacement for self.

> 
> I''m thinking the word 'self', at least in English, is too '3rd person'
> in some ways, and looking down on a lot of objects, each with a
> 'self', you have only a god's eye view.  However, the grammar around
> 'me' is different -- there's only one of them (one first person), and
> therefore thinking "me" promotes a kind of first person instrospective
> attitude.  And we *want* that, as an option, when modeling in OO.
> 

For instance

class Human (object):

 def __init__(human, name):
 human.name = name

 def __repr__(human):
 return 'Hi, my name is %s' % human.name

so expressing, that the first parameter just names that
special instance of the class, which is meant in the
current context.

Insisting on this, I'd to add, that 'self' is not enough '3rd person',
which I don't do. I just wanted to add an additional point of view.

I write this not only for fun, but I've made the experience
(with students as well with teachers) that this approach also
can enhance their understanding of the *mechanisms* of OOP.
(altough not, perhaps, their ability to do object oriented design).

Regards,
Gregor



___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Alan Kay - another one of his ideas

2006-07-12 Thread Gregor Lingl
kirby urner schrieb:
> On 7/12/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>   
>> But, I remain willing to be wrong here.  Just that there is an inevitability
>> about other peoples' sense of where we are *necessarily* going that I don't 
>> share,
>> and to the extent we *necessarily* get there I would like to be sure that we
>> get there as something more than a prophecy, self-fulfilled.
>>
>> Art
>> 
>
> I think we each have a responsibility to trailblaze, to pioneer, in
> the direction of a future we consider promising and attainable.
>
> We don't all share the same vision, but in expressing our respective
> preferred futures as clearly as we're able, we at least have something
> to bring to the table.
>
> I think you bring a lot to the table, and do responsibly demonstrate
> what you consider worthy of study and further development (Euclid,
> Klein, Pygeo etc.).
>   
Regardless of the subject line your and Arthur's discussions seem
to have some strange attractor.
(Just an observation. Or am I wrong?)
Gregor
> Kirby
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
>   

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Alan Kay - corrected link

2006-07-11 Thread Gregor Lingl
Gregor Lingl schrieb:
> Hi everyone,
> let's go on pragmatically ;-)
>
> Recently Daniel Ajoy on LogoForum posted a link to a description of one 
> of Alan Kay's projects, called logowiki, by himself:
>   
Correct link:

http://www.redhat.com/archives/olpc-software/2006-April/msg00035.html

gl
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] Alan Kay - another one of his ideas

2006-07-11 Thread Gregor Lingl
Hi everyone,
let's go on pragmatically ;-)

Recently Daniel Ajoy on LogoForum posted a link to a description of one 
of Alan Kay's projects, called logowiki, by himself:

http://www.redhat.com/archives/olpc-software/ 
2006-April/msg00035.html

Worth reading!  He not only writes about how this project fits into his 
"children first" efforts, but also (in some detail) about the  
difficulties of implementing such a system using DOM and JavaScript). 
And he manages it easily to mention Smalltalk only once, marginally ;-)
Imho in the first place his initiative has to be considered as a 
political one. (As is the initiative to reimplement Squeak in Python.)

The logowiki can be found here:

http://www.logowiki.net

I wonder if something similar could be done for Python easily? For 
instance using xturtle, which is built on a rather small graphics interface.

I think the project has some similarities with Andre Roberge's Crunchy Frog.

A thing like this certainly could be another building block in our 
efforts to bring Python to the people. 

Perhaps one of the web frameworks TurtboGears or Django or the 
Ajax-people have some ressources ready to implement this.

So I've simply two questions:

(1) Which Frameworks, Libraries, tools are adequate for a Python project 
similar to logo-wiki?

(2) Who is interested in undertaking it or assisting it?

Regards,
Gregor




___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] The best way to predict the future...

2006-07-11 Thread Gregor Lingl
kirby urner schrieb:
> OK Arthur, that's more clear, what you're saying.
>   
Alas, not for me! I must complain that I simply do not understand large 
parts
 of this intellectually and psychologically outstanding conversation.  
Just as an
example: it took me about 10 minutes to find out the meaning of 'smarminess'

Perhaps a more pragmatical and less psychosicial philosophical approach 
would
also bring some benefits.

Given the fact, that I'm not really sure, what's going on here, I'll 
comment only one
section of your recent posting.
> But the reality is:  teachers are afraid of Python, of hackers, of
> geekdom, of technology.  We live in a culture of fear and ignorance.
> We had that student on earlier, complaining he couldn't demo has class
> project, because even a Linux boot CD was to scary for the school's IT
> cult.  They regarded it as a threat to their authority.
>   
This is simply nonsense (and to some degree even a dangerous point of view)
 - at least seen from my point of view as an Austrian teacher. (I would 
be interested
to know if the situation in the USA/Canada is completely different from 
ours.)

In my experience, nowdays teachers are overloaded with  a huge set of 
different
tasks, many of them belonging more to the branch of social work than to that
of education.  To do their work succesfully they have to educate 
themselves -
continually for instance in seminars - about things like 'social learning',
confilct management, coaching and many more similar things.

( There are many reasons for this, the main one beeing that there is not 
enough
money spent for the educational sector by the state. )

Those who teach computer science normally teach also other subjects like 
maths,
physics or even Latin or religious education. The computer education 
part normally
comprises 20 percent plus/minus of their teaching obligations.

They are overwhelmed by an incredibly enourmous amount of new 
developments in
this sector and they have to choose which parts of them first to *learn* 
(for themselves)
and then to *teach*.

They are not afraid of - whatever - but they are under an enormous 
pressure and have
to make a "clever" and economical (in terms of time and other 
ressources)  decision.

I for my part consider it to be my obligation to show, that the choice 
of Python as
a first programming language is a clever one (in several respects I need 
not talk about
here). I did this by writing a book for kids _and_teachers_, by 
providing the
xturtle module which (imho) meets just those requirements, by giving 
advanced
teacher's trainig courses and so on.

The reality is, that you have to accept, that 98% of the cs teachers are not
computer geeks/freaks/nerds like Kirby, Arthur, Andre (and perhaps to
la esser degree me) - but they are surely interested to do a good job taking
into accoutn their limited ressources.

What can we do? We can try to reach them and convince them, that our 
approach
is practical. Or we can try to change the politics concerning the 
educational sector
of the society in order to achieve better conditions for education 
(harder!).

Or both.

Regards,
Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] xturtle - talk at EuroPython2006

2006-07-11 Thread Gregor Lingl
Hi everyone,

the slides to my talk at Europython2006

*xturtle - an extended turtle module for Python
as a vehicle for teaching programming concepts*

are now available:


http://indico.cern.ch/materialDisplay.py?contribId=100&sessionId=52&materialId=slides&confId=44


Regards,
Gregor


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] News about turtle graphics

2006-06-29 Thread Gregor Lingl
Brad Miller schrieb:
> Hi Gregor,
>
> The more I play with the new xturtle the more I like it.  Thanks!  
> I've been thinking about the following extension to TurtleScreenBase 
> and I wonder what you and others think of the idea.
>
> I like the fact that the turtle starts out in a coordinate system with 
> 0,0 in the middle of the window, and I like the fact that for 
> beginning students 1 unit == 1 pixel on the screen.  But, I think that 
> after a student has used the turtle to plot a sin or cos curve and 
> learned about scaling the values to make the plot visible in the 
> window it would be nice to place the turtle in a world coordinate 
> system that matched whatever application the student was working on.  
> For example the gravitaion examples could be done in meters.  Let 
> TurtleScreenBase take care of the translation and scaling after for 
> you.  The API could be extended by a single call 
> setWorldCoordinates(llx,lly,ulx,uly) that specifies the world 
> coordinates of the lower left corner of the screen and the upper 
> right.   (This is very similar to the ortho2 call in openGL.  Note, if 
> the student does not call setWorldCoordinates then the turtle 
> functions just as it does now.
>
> I've already added this capability to the turtle.py that Vern wrote 
> for Python 2.5 and I don't think it would be too hard to add to 
> TurtleScreenBase.  What do you all think?  Would this be a useful 
> addition?  Gregor, is this something you already have on your todo 
> list?  Would you be interested?
>
I've thought about this,but abandoned it for the moment. The xturtle API 
is already
rather 'fat' as the core developers complained.

I'll appreciate your proposal. So do it, for now as an experiment.
At the moment I'm very busy (and have to concentrate on my Europython talk),
but I've several points to say on this. Please wait until end of next 
week, then
I'll be ready to discuss this in depth.

Thanks again for your idea
Gregor

(P.S.: When you have done his enhancement, perhaps you could devise
some interesting gravitational systems with real world coordinates?)

> Thanks,
>
> Brad
>

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Sample Data Structure

2006-06-27 Thread Gregor Lingl
kirby urner schrieb:
>> I doubt if it is a good choice to use a dictionary here, as this is not
>> an ordered data
>> structure and interchanging the layers of  the cube will certainly make
>> the cube
>> imperfect.
>
> Yes, I think you're right. I was trying to advertise dictionary
> syntax, but not appropriately in this case.  My earlier draft was
> nested tuples, and I could have stuck with that, but thought it too
> boring.
>
> A more complete module would also have audit code that actually summed
> all the rows, columns and diagonals, and spit out 315 every time.
>
> I've written most of this auditing code, but decided the bare data
> would be better.
>
I did a similar thing, deciding to use a flat list. If one used the flat 
list *and* the
(given) nested one(s) one could make the code even more compact.

My solution goes like this:

from operator import __and__

magic5 = [

[[25, 16, 80, 104, 90],
 [115, 98, 4, 1, 97],
 [42, 111, 85, 2, 75],
 [66, 72, 27, 102, 48],
 [67, 18, 119, 106, 5]],

[[91, 77, 71, 6, 70],
 [52, 64, 117, 69, 13],
 [30, 118, 21, 123, 23],
 [26, 39, 92, 44, 114],
 [116, 17, 14, 73, 95]],

[[47, 61, 45, 76, 86],
 [107, 43, 38, 33, 94],
 [89, 68, 63, 58, 37],
 [32, 93, 88, 83, 19],
 [40, 50, 81, 65, 79]],

[[31, 53, 112, 109, 10],
 [12, 82, 34, 87, 100],
 [103, 3, 105, 8, 96],
 [113, 57, 9, 62, 74],
 [56, 120, 55, 49, 35]],

[[121, 108, 7, 20, 59],
 [29, 28, 122, 125, 11],
 [51, 15, 41, 124, 84],
 [78, 54, 99, 24, 60],
 [36, 110, 46, 22, 101]]
]

def flatten(lol):
flat = []
for l in lol:
flat.extend(l)
return flat

## This approach - using slices - operates best with a flat list

def msq(s):
return reduce(__and__, (
  [sum(s[i:i+5])==315 for i in range(0,25,5)] +
  [sum(s[i:25:5])==315 for i in range(5)] +
  [sum(s[0:25:6])==315, sum(s[4:21:4])==315]))

def magic(cube):
sq=flatten([flatten(sq) for sq in cube])
return reduce(__and__, (
  [msq(sq[i:i+25]) for i in range(0,125,25)] +
  [msq(sq[i:125:5]) for i in range(5)] +
  [msq(flatten([sq[i+j:i+j+5] for i in 
range(0,125,25)])) for j in range(0,21,5)] +
  [sum(s)==315 for s in 
[sq[0:125:31],sq[20:105:21],sq[4:121:29],sq[24:101:19]]]))


print magic(magic5)

# I wonder how it will look like with a 3-dimensional list

Regards,
Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Sample Data Structure

2006-06-26 Thread Gregor Lingl
kirby urner schrieb:
> So here'd be a rich data structure transcribed from Math World:
> http://mathworld.wolfram.com/news/2003-11-18/magiccube/
>
> Possible lesson plan:  use as mapped and indexed data structure to
> verify we're meeting the requisite criteria for a perfect magic cube
> of edges 5 cells.
>
> magic5 = dict (
>
> square0 =
> [[25, 16, 80, 104, 90],
> [115, 98, 4, 1, 97],
> [42, 111, 85, 2, 75],
> [66, 72, 27, 102, 48],
> [67, 18, 119, 106, 5]],
>
>   

I doubt if it is a good choice to use a dictionary here, as this is not 
an ordered data
structure and interchanging the layers of  the cube will certainly make 
the cube
imperfect.

I suppose a 5 element list would be more appropriate.

Regards
Gregor


> square1 =
> [[91, 77, 71, 6, 70],
>  [52, 64, 117, 69, 13],
>  [30, 118, 21, 123, 23],
>  [26, 39, 92, 44, 114],
>  [116, 17, 14, 73, 95]],
>
> square2 =
> [[47, 61, 45, 76, 86],
>  [107, 43, 38, 33, 94],
>  [89, 68, 63, 58, 37],
>  [32, 93, 88, 83, 19],
>  [40, 50, 81, 65, 79]],
>
> square3 =
> [[31, 53, 112, 109, 10],
>  [12, 82, 34, 87, 100],
>  [103, 3, 105, 8, 96],
>  [113, 57, 9, 62, 74],
>  [56, 120, 55, 49, 35]],
>
> square4 =
> [[121, 108, 7, 20, 59],
>  [29, 28, 122, 125, 11],
>  [51, 15, 41, 124, 84],
>  [78, 54, 99, 24, 60],
>  [36, 110, 46, 22, 101]]
> )
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
>   

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] Some thoughts on RurPle / TurTle

2006-06-25 Thread Gregor Lingl
Andre and me, we had an exchange of thoughts on RUR-PLE and xturtle
and their respective goals. Perhaps someone might be interested ...

On 6/25/06, Gregor Lingl <[EMAIL PROTECTED]> wrote:
> Andre Roberge schrieb:
> > On 6/25/06, Gregor Lingl <[EMAIL PROTECTED]> wrote:
[snip]
> >
> > As long as you have a look at rur-ple and tell me what you think. ;-)
> >
> O.k., I had a short look at it, I liked it, especially the very well
> designed
> user interface. I don't have time now (before my talk at Europython and
> before having finished the second edition of my book, which will have
> significant changes because it will use my new xturtle)

Thanks for taking the time to have a look at it.  I understand
completely about the lack of time to do everything that one might want
to do.

> 20 years ago (i mentioned it somewhen) I wrote a Karel descendant
> "The very very tiny robot programming system" (in Turbo Pascal)
> for an Austrian schoolbook, which of course now is way out of date.
> It was a big success then and was used for about 15 years.

You are years ahead of me!... I just started this (and only for fun, I
don't use it myself as I don't teach) less than 2 years ago.

I just noticed your email address (and your reference to Austria) - I
had assume you were from Germany.  I had the pleasure last year of
visiting briefly your country.  I took part in a "trade mission" to
the town of Güssing to have a look at the renewable energy
infrastructure.  I live in a small rural town in Canada and we are
thinking of implementing a similar infrastructure here... but that's
another story.

> In this book Pascal was tought.  At the same  time in  Austria  Logo
> became popular and I gave seminars for teachers in Logo programming,
> and later also for students.
>
> So I learned  both approaches and imo there is one significant difference
> between them: The Karel-the-Robot approach has a far more restricted
> "universe" than Turtle-Graphics which has a "open universe". This is
> reflected
> (in Karel, in my tinytiny... as well as in RUR-PLE (how do you pronounce
> it?))
> in that they had and have very well designed introductory lessons with very
> specific tasks to solve.
>

1. I pronounce it like the colour "purple".
2. I totally agree with your statement about "open" vs "closed"
universe.  I had been thinking of including a "fifth notebook page"
within rur-ple, which would have been a turtle graphics one, where the
robot world is replaced by a turtle canvas.  That being said, I
believe that there is an advantage to having a slightly restrictive
universe initially.  I will explain below.

> In  contrast to this in the turtle-graphics approach prevails the attitude
> to let the students find their own tasks, and the programming environment
> must be thus rich that solutions can be found. Therefore I provided
> my xtx-examples, which indeed  comprise  a very  broad range of different
> problem areas.
>
> There is one important feature in your RURPLE (as you mentioned
> lately)  that you  do not use a special  RURPLE language but Python
> (do I rember correctly, that this is also a difference to GvR?), which
> I consider a big advantage.

This is something I believe in as well.  My goal is to provide an
introduction to programming which is as "smooth" as possible.  We
sometime hear the phrase "steep learning curve" to characterize some
difficult to grasp concept.  I think it is important to have as few
"steep learning curves" as possible in the learning process.   GvR
uses a slightly easier syntax than Python ... but at the expense of
having a "step-like learning curve" when one wants to go from GvR's
world to Python programming.  Since Rur-ple uses Python, there is no
transition to speak of.

Also, because rur-ple basic instructions [move(), pick_beeper(),
put_beeper(), turn_left(), turn_off()] are very limited, they are
easier to learn and build from, I think, than the corresponding turtle
graphics where one has to contend with arbitrary rotations and
arbitrary step lengths right from the start...  This is, I believe,
one advantage of having a "closed universe", at least at the
beginning.   What I would like to do (eventually) is to add
turtle-like features to rur-ple, with something like
move() -->  move(length)
turn_left() -->  turn(angle)
and have an open canvas.  I think this would combine the best of both worlds.

Finally, to go back to the use of Python in rur-ple, I implemented
both a procedural approach [move(), turn_left()] as well as an object
oriented approach
Reeborg = UsedRobot()
Reeborg.move()
Reebord.turn_left()

again with the idea of providing a "smooth" transition to more
advanced concepts.  I im

[Edu-sig] onClick(goto)

2006-06-24 Thread Gregor Lingl
Hi all of you!

In a previous post I used
 >>> onClick(goto).
No reaction. Hmmm... (perhaps nobody clicked)

For those of you, who didn't have the opportunity to look
into the xturtle.py  package, here is a typical untypical
example for the use of xturtle, 25 lines of code,
say painter.py:

""" A tiny paint program.

After startup use mouse-buttons:
left   - to move pen
right  - to switch penstate from up to down and
 vice versa. switching to up begins filling,
 to down ends (and performs) filling
middle - to switch color (you may use different colors
 for drawing lines and filling)

draw and have fun!
"""

from xturtle import *

def switchupdown(x, y):
if pen()["pendown"]:
end_fill()
up()
else:
down()
begin_fill()

def changecolor(x, y):
colors.append(colors.pop(0))
color(colors[0])

shape("circle")
resizemode("user")
turtlesize(0.5)
width(3)
colors=["red", "green", "blue", "yellow"]
color(colors[0])
up()
onClick(goto,1)
onClick(changecolor,2)
onClick(switchupdown,3)
mainloop()  ## comment out if used from within IDLE with -n switch

### end of program

I think, this example shows, that fairly simple use
of fairly advanced concepts can lead to a fairly
funny result.

Try it out.
Have a nice weekend.

Gregor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] [edupython] Re: News about turtle graphics

2006-06-23 Thread Gregor Lingl
Vern Ceder schrieb:
> Gregor,
>
> Well done! xturtle.py is a truly impressive re-implementation and 
> enhancement. I ran all of the demos without problems on a Linux (Ubuntu 
> Dapper) machine and was very impressed with the speed, as well as the 
> number, variety and quality of the demos.
>
> I would certainly think that (after testing ;) ) xturtle might replace 
> the current turtle.py. 
btw, who is responsible for a decision about this? I even don't know 
whom I should contact.
I think you should know ;-)
> I had also been thinking about what would be 
> involved in porting turtle.py to Jython and your refactoring makes that 
> a much more appealing possibility.
>   
If you have more concrete ideas concerning this, please let me know.
> I saw that you were presenting at EuroPython - best of luck with that 
> presentation. I'll be presenting on Python programming at NECC, a 
> national educational computing conference, on July 7, so if you don't 
> mind I will mention xturtle then.
>
>   
Of course not. (Naturally) I'm very interested in making xturtle 
pupular. I did it because I'm
convinced that it could help popularize (is this an English word?) 
Python in the educational
arena as well as make life of the educators a bit easier (and funnier (- 
in the sens of 'Have fun!')).

> One final thought - even though the file is large, I would consider 
> including at least some demo code in the file itself. Maybe it's just 
> me, but I like the idea of being able to demo the module even if it gets 
> separated from all other files in the package. Things like that can 
> happen. :)
>   
That's right. One could use 'oldTurtleDemo.py' for this (now that gets 
imported). I'll think about it
and perhaps I'll have some ideas to make it more funny  I'll do a 
proposal.

(I'm glad, that  all of you expressed, that you like xturtle much!)

Best wishes
Gregor
> Cheers,
> Vern
>   
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] [edupython] News about turtle graphics

2006-06-23 Thread Gregor Lingl
kirby urner schrieb:
> Yes, I'm liking the demos too and will say something in my blog today.
> Question:  say a student has just booted IDLE and wants to run the
> minimum import and turtle commands to draw a triangle, what would that
> look like?  
IDLE 1.2b1   No Subprocess 
 >>> from xturtle import *
 >>> onClick(goto)
 >>>

;-)
> I believe I will be able to answer my own question with
> just a little more study.  I am wondering if an xturtle package with
> an __ini__.py would make sense.
>
What for?
Gregor
> Kirby
>

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] [edupython] News about turtle graphics

2006-06-23 Thread Gregor Lingl
Dethe Elza schrieb:
> Hi Gregor,
>
> I tried it out on OS X and it works great.  There are some very
> beautiful demos.  I will try to dig under the hood at some point and
> see if it would be feasible to replace Tinker with Cocoa
> (conditionally, if the user has PyObjC installed, otherwise it could
> fall back to Tkinter).
>
>   
Ah fine, please do so - (and keep us informed).
There is one single class, TurtleScreenBase, which contains the 
interface to Tkinter. It was
one of my primary design decisions, to keep this small and isolated. (I 
had in mind e.g. porting
it to Jython). So at first concentrate on that small part of the thing.

Unfortunately this part of the software is still not very well 
documented (albeit it doesn't
contain special intricacies). If you have questions, feel free to ask.

(Of course that doesn't apply to the demoViewer ...)

Best wishes
Gregor
> Putting it into Javascript would probably be possible, and there is
> even a workaround for  in IE, but the performance would
> definitely take a hit.
>
> Great work.  I should take a look at Rur-ple now...
>
> --Dethe
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
>   

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] News about turtle graphics

2006-06-22 Thread Gregor Lingl
Hi educators!

One of the hardest problems I've encountered upto now
is to decide, when a piece of software is ready to be
be published.

I've decided, that my new turtle graphics module ready
now. A package, which additionally contains some
example scripts. a tiny demoViewer and some documentation
can be downloaded from:

http://ada.rg16.asn-wien.ac.at/~python/xturtle

 From now on it's the user community, which will largely
determine the future development of the module. I hope
that it will grow to more than one user (which is me)
soon. (*) And I'm willing to continue development (preferably
in cooperation with others) until it's considered a really
useful tool by the community.

In my opinion it should replace the current turtle.py in
the standard distribution. We will see if others join
me in this respect ...

(Please note, that xturtle.py is a complete reimplementation
of what I've shown to you some ten weeks ago.)

For now I'll not write too much about it, but ask you for
feedback and contributions to a discussion about the module.
(You'll find some more information on the webpage mentioned
above!)

However, I'll give a talk at Europython 2006 on July 5th about:

xturtle - an extended turtle module for Python as a vehicle
for teaching programming concepts.

For this, too, your feedback will be welcome. And you'll get
back the slides of the talk ;-)

Regards,
Gregor Lingl

(*) This hope seems reasonable since I intend to use it in
the forthcoming 2nd edition of "Python für Kids"


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] The end is near :)

2006-04-11 Thread Gregor Lingl


Peter Bowyer schrieb:
> At 01:39 11/04/2006, Andre Roberge wrote:
> 
...> In the meantime, if anyone wants to read and comment on a 35 page
> document on the rationale behind teaching introductory programming 
> using Python, I have one :)
> 

Me too, please ...
Gregor

> Kind regards,
> Peter
> 

-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] From europython -- should we do Python for kids?

2006-03-22 Thread Gregor Lingl


Laura Creighton schrieb:
> I think doing this would be fun.  Since the CFP hasn't gone out
> yet, we haven't really organised ourselves all that well yet.
> 
> But I think that Introductory Python is a good idea.  I wonder if
> a separate Python-for-the-kids section would be good as well, and
> how many kids we could get to Europython if we offered this?
> 
> What do other people think of this?
> 

I'm considering to attend Europython this year - as it will take place 
in Switzerland, which is not far from Austria ;-) and also after the end 
of the school year in (eastern) Austria.

Moreover I considered to give a short talk about, or presentation of, 
the turtle module I'm currently developing.

Incidentally I've written a book "Python für Kids" (in German), a second 
  edition of which I'm going to prepare this summer.

So you can imagine that  I would definitely be very interested in some 
event like the one you proposed - as well as to further the use of 
Python in education in general.

As far as I know there was an educational track last year at Europython. 
   Will this also be the case this year. What will (or should) be the 
relation to "Python for kids" that track? (part of? replacement?)

** Oh, I just noticed that your posting was a reply to some posting 
elsewhere.**

In principle I also can imagine to give some beginner course ...

Sorry for ending this posting so abruptly - it's early in the morning 
here and I've to go to work. Will be back in the evening.

Regards,
Gregor Lingl

> Laura, brainstorming
> 
> --- Forwarded Message
> 
> Return-Path: [EMAIL PROTECTED]
> Delivery-Date: Wed Mar 22 23:27:56 2006
> To: europython@python.org
> From: Jan Ulrich Hasecke <[EMAIL PROTECTED]>
> Date: Wed, 22 Mar 2006 11:37:10 +0100
> 
> Subject: [EuroPython] Python for Kids?
> X-BeenThere: europython@python.org
> 
> Hello,
> 
> I am interested to register for the europython and would like to come  
> with my son. He is 13 and has started to program with python 2 years  
> ago. He is interested in the game track of course. Are there any  
> other events for "kids", interested in learning python?
> 
> There is a very good book around in German "Python for Kids" for  
> example. 

Danke für die Blumen!

Are you planning to do some beginner courses or courses for
> advanced beginners?
> 
> Sincerely
> Jan Ulrich Hasecke
> 
> DZUG e.V. - Deutschsprachige Zope User Group - www.zope.de -  
> www.dzug.org
> Forster Straße 29 - 06112 Halle/Saale
> Telefon +49 345 122 9889 9 - Fax +49 345 122 9889 1
> 
> 
> 
> ___
> EuroPython mailing list
> EuroPython@python.org
> http://mail.python.org/mailman/listinfo/europython
> 
> --- End of Forwarded Message
> 
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
> 
> 

-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Getting ready for class...

2006-03-09 Thread Gregor Lingl


kirby urner schrieb:
> Here's what I'm starting with today:
> 
> http://www.4dsolutions.net/ocn/python/zoo.py
> 
> Note:  inheriting from object at the top level, per André's suggestion.
> 
> Kirby
> 

I also like this example very much (especially the somewhat 
sophisticated use of __repr__).

Despite of the lack of echo to my former (turtle-)example I'd like to 
contribute one more - this one without turtles (the English translation 
may be a bit inept):

In my class I let the students do the following exercise to sum up or 
recapitulate what they have learned in previous lessons about objects, 
inheritance and message passing:

We begin very simply (who wants may inherit from object):

 >>> class Messenger:
 def announce(self):
 print "I announce to you:", "Hello!"


 >>> herold = Messenger()
 >>> herold.announce()
I announce to you: Hello!
 >>> annunciator = Messenger()
 >>> annunciator.announce()
I announce to you: Hello!
 >>>

 Not very diversified ... We improve it:

 >>> class Messenger:
 def announce(self, text):
 print "I announce to you:", text


 >>> herold = Messenger()
 >>> herold.announce("Fire on the roof")
I announce to you: Fire on the roof
 >>> herold.announce("Hurricane approaching!")
I announce to you: Hurricane approaching!
 >>>

 Now we want the messengers to remember their message text:

 >>> class CleverMessenger:
 def note(self, text):
 self.message = text
 def announce(self):
 print "I announce to you:", self.message


 >>> wiseguy = CleverMessenger()
 >>> wiseguy.note("Shares are rising!")
 >>> wiseguy.announce()
I announce to you: Shares are rising!
 >>> vifzac = CleverMessenger()
 >>> vifzac.note("Weather is becoming cold!")
 >>> vifzac.announce()
I announce to you: Weather is becoming cold!
 >>>
 >>> vifzac.note("Weather is becoming warm!")
 >>> vifzac.announce()
I announce to you: Weather is becoming warm!
 >>> vifzac.message
'Weather is becoming warm!'

 ( A look at an attribute )

 Now inheritance: A VeryCleverMessenger 'isa' CleverMessenger

 >>> class VeryCleverMessenger(CleverMessenger):
 def note_additionally(self, addendum):
 self.message = self.message+" "+addendum

 >>> angelo = VeryCleverMessenger()
 >>> angelo.note("It's becoming cold!")
 >>> angelo.announce()
I announce to you: It's becoming cold!
 >>> angelo.note_additionally("Use warm clothing!")
 >>> angelo.announce()
I announce to you: It's becoming cold! Use warm clothing!
 >>> merkur = CleverMessenger()
 >>> merkur.note("Traffic jam on all Highways!")
 >>> merkur.note_additionally("Defer trip!")

Traceback (most recent call last):
   File "", line 1, in -toplevel-
 merkur.note_additionally("Defer trip!")
AttributeError: CleverMessenger instance has no attribute 
'note_additionally'

 We see: merkur is not very clever

 The following shows a serious defect of our messenger classes

 >>> zweistein = VeryCleverMessenger()
 >>> zweistein.announce()
I announce to you:

Traceback (most recent call last):
   File "", line 1, in -toplevel-
 zweistein.announce()
   File "", line 5, in announce
 print "I announce to you:", self.message
AttributeError: VeryCleverMessenger instance has no attribute 'message'

 We will repair this by initializing the message attribute:

 >>> class CleverMessenger:
 def __init__(self):
 self.message="Hi!"
 def note(self, text):
 self.message = text
 def announce(self):
 print "I announce to you:", self.message


 >>> class VeryCleverMessenger(CleverMessenger):
 def note_additionally(self, addendum):
 self.message = self.message+" "+addendum

 >>> zweistein = VeryCleverMessenger()
 >>> zweistein.announce()
I announce to you: Hi!

 One more inheritance example:

 >>> class FriendlyMessenger(CleverMessenger):
 def __init__(self, greeting):
 CleverMessenger.__init__(self)
 self.greeting = greeting
 def greet(self):
 print self.greeting

 >>> sunny = FriendlyMessenger("Have a nice day!")
 >>> sunny.greet()
Have a nice day!
 >>> sunny.announce()
I announce to you: Hi!

 Overwrite methods

 >>> class FriendlyMessenger(CleverMessenger):
 def __init__(self, greeting):
 CleverMessenger.__init__(self)
 self.greeting = greeting
 def greet(self):
 print self.greeting
 def announce(self):
 self.greet()
 CleverMessenger.announce(self)

 >>> sunny = FriendlyMessenger("Have a nice day!")
 >>> sunny.announce()
Have a nice day!
I announce to you: Hi!
 >>> sunny.note("OOP is pretty useful!")
 >>> sunny.announce()
Have a nice day!
I announce to you: OOP is pretty useful!
 >>> tim = CleverMessenger()
 >>> tim.note("Tomorrow it will happen!")
 >>> tim.announce()
I announce to you: Tomorrow it will happen!

 Last example: communicating objects

 >>> class Agent(CleverMessenger):
 def passMessage(self, agent):
 agent.note(self.message)
 def listen(self, a

Re: [Edu-sig] Getting ready for class...

2006-03-09 Thread Gregor Lingl


Andre Roberge schrieb:
> On 3/9/06, kirby urner <[EMAIL PROTECTED]> wrote:
> 
>>Here's what I'm starting with today:
>>
>>http://www.4dsolutions.net/ocn/python/zoo.py
>>
>>Note:  inheriting from object at the top level, per André's suggestion.
>>
>>Kirby
> 
> 
> I like your examples. I imagine you are presenting them to the same
> group of students you mentioned before.  One example that I've seen on
> comp.lang.python which I really like, especially because it has a
> second level of inheritance, is the following (original by John
> Gabriele, with comments modified slightly here):
> 

Sorry Andre, but I really dislike this example. For me and in my lessons 
   inheritance is connected to an "isa" relation.

A Monkey isa Mammal etc.

This is violated here and i consider the confusion, which would be 
caused by this example, would outweigh the benefits, if any ...

This doesn't work:

A parent "isa" grand_parent ? - no! A child "isa" parent ? - no! I 
understand that the exmples goes about inheriting habits or opinions, 
but I really think this shouldn't be done this way

Regards

Gregor

> #-
> class Grand_parent( object ):
> 
>  def speak( self ):
>  print 'Grand_parent.speak()'
>  self.advise()
> 
>  def advise( self ):
>  print 'Grand_parent.advise()'
>  self.critique()
> 
>  def critique( self ):
>  print 'Grand_parent.critique()'
> 
> #-
> class Parent( Grand_parent ):
> 
>  def speak( self ):
>  print '\tParent.speak()'
>  self.advise()
> 
>  def advise( self ):
>  print '\tParent.advise()'
>  self.critique()
> 
>  # The Parent inherits his criticism method from his/her own parent
> 
> #-
> class Child( Parent ):
> 
>  def speak( self ):
>  print '\t\tChild.speak()'
>  self.advise()
> 
>  # Currently, the Child has no really useful advice to give.  The
> child will just
>  # parrot what he/she hears the parent say.
> 
>  def critique( self ):
>  print '\t\tChild.critique()'
> 
> #-
> print 'speak() calls advise(), then advise() calls critique().'
> print
> 
> people = [ Grand_parent(), Parent(), Child() ]
> for person in people:
>  person.speak()
>  print
> 
> 
> The output is:
> 
> speak() calls advise(), then advise() calls critique().
> 
> Grand_parent.speak()
> Grand_parent.advise()
> Grand_parent.critique()
> 
>  Parent.speak()
>  Parent.advise()
> Grand_parent.critique()
> 
>  Child.speak()
>  Parent.advise()
>  Child.critique()
> 
> André
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
> 
> 

-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Introducing classes (from functions to methods)

2006-03-06 Thread Gregor Lingl


Andre Roberge wrote:
> ... I thought of how I would go
> about to introduce classes, to users of rur-ple that have already
> written simple programs to make a robot (Reeborg) move in his world,
> both using the "function" notation and the OOP notation.
> 
...

Hi Andre and all of you,
may I give you a short sketch of my approach to this problem, just as a 
supplement to your approach. It mainly deals with the transition from 
writing functions to writing (classes and) methods and understanding the 
role of the self parameter:

You surely will not be surprised, that I do it with turtles. For your 
convenience with standard turtle.py  ;-)

Say, my students have written a short function

 >>> def polystep(length, angle):
forward(length)
left(angle)

to make the (anonymous) turtle (more exactly: Pen) draw spirals like

 >>> for l in range(4,80,4):
polystep(l, 90)

Sometimes we say, we have taught the turtle a new word: polystep. So she 
now knows how to polystep.

Say, my students then have learned to use turtle objects:

 >>> joe=Pen()
 >>> ann=Pen()
 >>> ann.left(180)
 >>> for turtle in joe, ann:
turtle.up()
turtle.forward(100)
turtle.down()

Wie now have two turtles at different positions on the screen. Now we 
want joe and ann to draw a spiral. We can do that this way:

 >>> for l in range(4,80,4):
for turtle in joe, ann:
turtle.forward(l)
turtle.left(90)

We would appreciate it, if joe and ann both knew how to polystep:

 >>> for l in range(4,80,4):
for turtle in joe, ann:
turtle.polystep(l,90)

So - as a first step towards our goal - we want to modify polystep in 
order to pass a turtle object to it. This way it would know which turtle 
should perform the polystep:

 >>> def polystep(turtle, length, angle):
turtle.forward(length)
turtle.left(angle)

Now we can make our spirals like this:

 >>> for l in range(4,80,4):
for turtle in joe, ann:
polystep(turtle,l,90)

We would prefer the last line to be:
 turtle.polystep(l,90)

i. e., that our turtles undertand how to polystep.

So we make a new class, (I omit some necessary explanations here
which you easily can fill in)

 >>> class MyPen(Pen):
pass

which we can immediately investigate, e.g.:

 >>> joe = MyPen()
 >>> ann = MyPen()
 >>> joe.color("red")
 >>> joe.forward(50)
 >>> ann.left(90)
 >>> ann.forward(50)
 >>>

So we see, that MyPens (i.e. MyPen instances) know everything Pens know. 
MyPen is a subclass of Pen:

 >>> isinstance(joe, MyPen)
True
 >>> isinstance(joe,Pen)
True

Every MyPen is a Pen

Now we want MyPens to know more thatn Pens. So we have to teach them 
something new: we make polystep a method of MyPen. (The students know 
methods, e.g. forward as a method of Pen):

 >>> class MyPen(Pen):
def polystep(turtle, length, angle):
turtle.forward(length)
turtle.left(angle)

We now can observe, that we have achieved, what we wanted:

 >>> joe = MyPen()
 >>> ann = MyPen()
 >>> ann.left(180)
 >>> for turtle in joe, ann:
turtle.up()
turtle.forward(100)
turtle.down()


 >>> for l in range(4,80,4):
for turtle in joe, ann:
turtle.polystep(l,90)

works as desired.

We now have to explain, why there are only two arguments in the call of 
polystep. Lets try (arbitrary) three:

 >>> joe.polystep(1,2,3)
Traceback (most recent call last):
   File "", line 1, in ?
 joe.polystep(1,2,3)
TypeError: polystep() takes exactly 3 arguments (4 given)
 >>>

This shows, what the Pythoninterpreter thinks about this call. He counts 
joe as a fourth argument. So

 >>> joe.polystep(50, 90)
in fact has passed three arguments to the polystep method of MyPen, joe 
beeing passed to the first one, turtle. Really? Really! It does the same 
  as:
 >>> MyPen.polystep(joe, 50, 90)

That means, that the interpreter passes the turtle it*self* (for which 
the method is called) to the first parameter of the method. Taking into 
account, that one may chose variable names freely, but should chose them 
so, that the names appropriately describe the meaning, we replace the 
name turtle by the name self (and explain that that is a convention in 
Python):

 >>> class MyPen(Pen):
    def polystep(self, length, angle):
self.forward(length)
self.left(angle)

This last step changes nothing, except (hopefully) enhancing our 
understanding of the process of moving on from defining functions to 
defining methods, and especially of the role of self.

Regards,
Gregor




-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] IDLE wish (was Edu-sig Digest, Vol 31, Issue 16)

2006-03-03 Thread Gregor Lingl


[EMAIL PROTECTED] schrieb:
> 
> - Original Message -
> From: Vern Ceder <[EMAIL PROTECTED]>
> 
>>I was asked submit the enhacements by Raymond Hettinger. I 
>>foolishly 
>>thought it might be good to ask for input on the nature of the 
>>improvements before doing so. If you want to have an argument 
>>about 
>>whethe turtle.py should be in the standard library at all, I would 
>>suggest you file a PEP or discuss it with the BDFL. It's far 
>>beyond me.
>>
> 
> 
> Just to be clearer, I have assumed that the turtle.py module in the standaerd 
> library
> is exactly the turtle.py module that the BDFL had judged was appropriate for
> the standard library.  And I never had a problem with it.  It is 
> appropriately minimal.
> 
> IMO, a less minimal one is less appropriate.

This statement seems to me, at least to say, a bit arrogant. Did you 
ever use turtle.py in an educational setting? If so you surely had a 
different view! You knew, for instance, that it has a number of serious
bugs. Things like this you call "approriately minimal".
Might it be rewarding for you, to supplement your opinion about 
turtle.py with some practical experience?

Regards,
Gregor

> Do you think I am arguing to argue, or do you at least believe that I mean
> what I say. And for reasons that may be judged wrong,  but are not outlandish 
> in
> any possible way.
> 
> Which is why I think a PEP might be nice to see if there is anyone else out
> there who sees it as I do.
> 
> Besides the fact that - before the issuance of the new memo I didn't get - 
> that ,at least 
> arguably, would just represent adherence to SOP. 
> 
> 
> Art
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
> 
> 

-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] IDLE wish (was Edu-sig Digest, Vol 31, Issue 16)

2006-03-03 Thread Gregor Lingl
Arthur schrieb:
>  
> 
> 
>>>-Original Message-
>>>From: Arthur [mailto:[EMAIL PROTECTED] 
>... 
> One argument against an "official" turtle.py module, is that it will be the
> Phone Company's Turtle, and the forces of agility and merit will be lost.
> To me it is better if folks wanting a serious turtle graphics implementation
> expect to look for it outside the standard distribution.
> 
> I am perfectly aware that my approach to these discussion is not likely to
> get me liked.  Kirby, we know, is weird ;).
> ...

Hi Arthur and all of you ...
we all really know very well that you don't like to liked, except
perhaps by Kirby. But that's really not the point when discussing about
changes in the turtle.py module.

To me this discussion already seems rather strange. There are (I think
quite a lot) of people, who use turtle.py, as a part of the standard
distribution of Python, for their educational work.

Some of them feel, that the module is not adequate for their needs and
they propose to enhance it. A procedure, done so many times with so many
Python modules. And just in that moment there come two protagonists of
the Pythonic educational scene and state: if you want to amend it, then
we find, that it would be better to delete it completely from the
standard distribution.

That's a really weird conclusion. And it lets me ask myself, what
interests stand behind this sort of argument?

My interests are clear. I've written a book "Python für/for Kids" which
relies heavily on the turtle module as a visualiziation tool. (And I've 
got a really nice preface from Guido.) So clearly I wouldn't like 
turtle.py found to be deleted from the Python distribution.

What I and most other users of the python module want and, I think, many
teachers need, is: you can install Python and use it - as was said "out
of the box" - with children and young student (and also older students)
and thus have fun. A bit more fun would be a bit better. This comprises 
among other things doing some graphics without having to learn the 
Tkinter machinery.

I not only teach students but also teachers. Many of the teachers of
what we call "Informatik", sort of computer science, have a big stress
not only with their daily school life, as they normally are also maths,
physics or teachers of some other subject, but also with keeping contact
to the progress in so many branches of computer science. They need tools
they can learn easily and teach easily to students who (at least the
largest par of them) don't want to become computer scientists. Thats a
kind of cp4e. (Many of the e's will not learn more than one computer 
language, at least in Austria ;-( )

And of course it has many more merits, as for instance making Python
more popular etc. etc.

(By the way: who of us uses the really good turtle module of PythonCard?
I assume only few, and I think, that is because it's not in the standard
distribution.)

But I don't want to argue on this any more, as most of it has already
been stated in this discussion.

In fact I would like to support the idea of Vernon Ceder to transfer the
discussion of the development of turtly.py to some separate place. 
Perhaps it would be  possible to host it at sourceforge or something 
like that and install  some mailing list, e.g. turtle-dev, on it for 
several month. On python.org there currently approximately 70, many of 
which are low traffic.

There are really many interesting questions to  discuss and that is not 
possible in a fruitful athmosphere on a list where two people who do 
more than 50% of the overall postings (in terms of number not to speak 
of volume, as it was in the last six month) dislike it. Moreover it 
would also be not interesting enough for the majority of the 
participants of Edu-Sig. So it would suffice to report progress and 
results from time to time here.

So Vernon, could you check which possibilities there are?

Regards,
Gregor


> 
> 
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
> 
> 

-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] turtle-rurple [Was Digest 31/16]

2006-03-01 Thread Gregor Lingl


Andre Roberge schrieb:

> I am *strongly* considering the inclusion of turtle graphics within RUR-PLE.
> However, since it is based on wxPython instead of Tkinter, I should probably
> rewrite it almost from scratch (so that I understand it, in any event ;-).
> 

Did you know, that there is a powerful turtle graphics module contained
in PythonCard - which is a wxPython extension as far as I know.
It has a lot of interesting examples

Gregor


-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] turtle-rurple [Was Digest 31/16]

2006-03-01 Thread Gregor Lingl


Andre Roberge schrieb:
> On 3/1/06, Gregor Lingl <[EMAIL PROTECTED]> wrote:
> [snip]
> 
>>...


> Have you (/they) considered something like Guido van Robot, or RUR-PLE?

When I was younger, in 1986, together with friends I wrote a schoolbook
called "Werkzeug Computer" ("Werkzeug"=tool). Then I implemented a 
version of "Karel the Robot" in Turbo Pascal. It was a complete IDE with 
syntax colouring, visual tracing etc etc. The compiled code was 64k - 20 
bytes approx, which was the utmost limit of Turbo Pascal 3.0 then. It 
was a big success and was used by some Austrian teachers until recently. 
(I think it still can be run in a DOS - Window.)

A short time afterwards I leared to know Logo, and so turtle graphics 
also. Now I find this more rewarding. It provides nearly every advantage
of the Robot plus a lot more freedom and space for new ideas. (*)

If I had the time, I'd like to translate also GvR or RUR_PLE to German,
but now I'm involved in my Turtle-Project and maybe there will be a 
second edition of my book "Python für Kids" - (I well remember, that you 
asked me for an English translation one or two years ago.)

During the last few month together with Mike Müller from Leipzig I've 
completed a (still "raw") translation of "How to think like a computer 
scientist - the Python way" to German.
(German readers may find it here:

http://ada.rg16.asn-wien.ac.at/~python/how2think/

and are invited for feedback ...)

You see, I'm really a fan of providing different ways ...

But currently RUR-PLE surpasses my capacities for the moment. If you 
know of a German translation on the way, let me know. Maybe I can put a
short section or at least a hint to it in my book)

Best wishes
Gregor

(*) If you tried out my Xturtle-examples you could easily grasp, what
I mean with this.

-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Edu-sig Digest, Vol 31, Issue 16

2006-03-01 Thread Gregor Lingl
 exception more than the rule.  That's 
> already the case here in Portland, in some schools anyway.  I hope South 
> Africa will get there shortly (you might think they have a long way to 
> go, but actually South Africa is poised for a great leap forward, in the 
> Chinese sense, but we hope without the same stumbling).
> 
> Kirby
> 
> 
> 
> 
> 
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig

-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] suggetions abaout turtle.py

2006-02-28 Thread Gregor Lingl
Hi all,

Apparently XturtlePkg.ZIP is to large(or wrong format)
to be sent over the Edu-SIG list, so if you want to
try it out, you are bound to use the mentioned link

http://ada.rg16.asn-wien.ac.at/~python/Xturtle/

to download it.

Regards,
Gregor


Gregor Lingl schrieb:
> Vern Ceder schrieb:
> 
>> Hello everyone,
>>
>>...
> 
> ___
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig

-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] suggetions abaout turtle.py

2006-02-28 Thread Gregor Lingl
  methods doesn't make 
sense. Also resizing the canvas would be a useful candidate (?).

(d) I'll add one more question as an example:
turtle.py has the function width() which sets the thickness of the lines 
to draw. There is no function to "get" it.
In Xturtle.py I've implemented pensize() (with width() as an alias) in a 
 way thatit can be used to set the pensize, when called with an 
argument and to return the current pensize when called without arguments.
Would you like this or would you prefer get- and set- functions() for 
each property? What is the "more pythonic" way?
There are many functions concerning pen-properties where this problem 
arises. They should be treated uniformly.



I'll close for now. Only a few remarks to the following:


So I think the following would be handy:

1. equally usable with either "import * from turtle" or "import turtle" 
imports


I think this is possible currently . What do you meadn exactly?
Something like "from turtle import Pen"?
2. should open with a window covering at least half the screen (the 
current default is too small to be useful)

Xturtle.py does so
3. should offer some simple configuration choices for things like 
initial size and shape, but mostly rely on reasonable defaults

ok, easy to do
4. should offer a class wrapper so that that one could easily 
instantiate different turtles for a first experience with objects.

I don't understand this question. Currently there are the classes
Pen and RawPen in th turtle module. The anonymous turtle is in fact
an instance of Pen (named _pen). It is easy to uses several turtles  at 
the same time.

5. some minor tweaks to make it better behaved when run from IDLE

I fear, these will become major tweaks ...
Does anyone have any feedback on these ideas or any other suggestions 
about how turtle.py might be improved without being fundamentally changed?


Note: this is about turtle.py only, for all its deficiencies. Any 
suggestions to try another library, system, or language will be 
cheerfully, but resolutely, ignored. ;)

OK - Xturtle uses no other library, system nor language - so please
do not ignore it - not even resolutely ;-)

Regards
Gregor

P.S.: Xturtle is here, along with its example programs:

http://ada.rg16.asn-wien.ac.at/~python/Xturtle/




Cheers,
Vern Ceder




--
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

Website: python4kids.net

2006-03-01

Xturtle.py is the prototype of a turtle module written in Python.
It is intended to serve as a first proposition what functions
and features I consider to be useful in a turtle module and what 
can easily be done in Python with Tkinter.

Starting point was the turtle module contained in the current
Python distribution. To a far extent this eXperimental turtle
module is compatible with turtle.py. 

The code is typical experimental. I'm currently doing a complete
rewrite, which I expect to be in a state of a "pre-alpha-release"
within about two weeks.

In the meantime there is much to discuss - see my posting on 
Python Edu-Sig.

The Xturtle-package contains

1. the Xturtle.py module  (eXperimental turtle module)
2. this document - mainly to discribe the
3. set of included examples
4. A documentation containing a description of (nearly) all 
   classes and functions contained in the module - written
   in German language :-(
   Nevertheless it may be useful for you, as you can see
   which functions with which parameter-lists are provided.
   And the function names are English anyway.
   It is in rtf-format
   
(At least I've translated most of the texts occuring in the
sample programs.)

=   
Important remark!
=

To do interactive turtle-graphics from IDLE, you have to
run IDLE with the -n-switch (No subprocesses!)

If you do so, your turtle-graphics programs must not contain
a mainloop() call.

There is only one example (Xplotter.py) which I recommend
to use with IDLE in this way. Interestingly in Windows
you can achieve this by opening the Python program by 
right-clicking with the mouse and chosing Edit with IDLE.
Then press F5 from the active editor - window to run 
the program. After the program has been run, you can give
additional graphics-commands from the IDLE shell window,
if you want and modify the graphics to your liking.


===
List of example-programs.
Under Windows you can run them by double-clicking them
in the windows explorer. Xturtle.py must be on the 
search path for modules. E.G. in the same directory
as the examples or in the directory where turtle.py lives.
===

There are examples from elementary to more elaborated.
Some of them I used for my teaching, some only to demonstrate
what can be done with turtle.py
They are not intended to serve as example

Re: [Edu-sig] question about livewires package. . .

2005-11-21 Thread Gregor Lingl


Scott David Daniels schrieb:
> Andy Judkis wrote:
> ...
> 
>>Livewires graphics routines behave differently under Python 2.4.1 than they 
>>...
> you can start Idle with the "separate process" feature disabled by
> changing the idle startup from something like: "python ...idle.pyw"
> to something like "python ...idle.pyw -n" -- start idle with no
> subprocesses.
> 
> on Windows:
>  copy the idle shortcut (right-click, menu item copy; right-click on
>  desktop, menu item paste).
>  Right-click on your new shortcut (now often called something like
>  "Copy of Idle") and choose properties. In the "General" tab, you
>  can fix the name to be something more to your liking. On the
>  shortcut tab, change the "Target" entry by append a space and a -n
>  to the target.
>  Click OK, and you have a new Idle button which does the one-process
>  Idle thing.
> 

Sometimes you may want to or have to do interactive graphics on one or 
more (Windows) machines where you can't or don't want to change the 
desktop etc. (e.g. you have to do a workshop somewhere etc...)

In this case the following trick will work:
Rightclick an arbitrary *.py progam in Windows Explorer and choose "edit 
with IDLE...". This also will open IDLE in the -n (or no subprocess) mode.

You may create a tiny program with the single statement

from Tkinter import *(or: from turtle import *)

and use this for the above trick.

Regards,
Gregor



-- 
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien

Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] re: CP4E (states cgi demo)

2005-04-11 Thread Gregor Lingl

[EMAIL PROTECTED] schrieb:
Kirby writes -

Certainly Unicode is another one of those key
topics that kids should check out early on.

god knows who will be helping
them with their homework ;)
it seems to me that if you and I were each
hooked up to geiger counters and the
word "Promethean" was flashed in front of us,
our needles would move in opposite
directions.
Are you sure that each of you 2 would use
geiger counters with needles?
Gregor
Art

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] reappearance of old postings

2005-03-25 Thread Gregor Lingl
Hi,
there just appeared a couple of postings from a Jan 2004 thread
(on primes) on this list again. (two of them by me)
To me it's completely unclear why and how this could
happen.
Does anybody know ...?
Gregor
--
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien
Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27
Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] Re: [Tutor] what? (late nite entertainment) (*)

2005-03-24 Thread Gregor Lingl

Now:  early morning corrections ...

Alfred Milgrom wrote:

> Hi Gregor:
>
> Hard to work out what is what :) as there seems to be a typo in one
> line of your code:
>
>if x[z]: x[z*z:n:z]=y[z*z:n:z]
>
> (At least it doesn't work on my machine with Python 2.2)
>
Yeah, I had the idea when playing around with some new features of
Python 2.3, as
I do sometimes late at night - before shutting down my computer. This
one I found at:

http://www.python.org/doc/2.3.3/whatsnew/section-slices.html

and I looked for an example for use of "assignment with extended slices" ...

> Also the subroutine breaks for n = 1 or less.
> Maybe you need a line at the start to say
> if n <2 : return [0]
>
what() was intended to generate all primes less than n. (In fact it's
an implementation of the sieve of Eratosthenes). The bugs came not
only from not beeing interested in primes less than 2  ;-) but also from
beeing a little tired already. Sorry.

I think the following version repairs that - and hopefully uses less
obfuscating variable names (which in fact originally was part of the
"riddle"):

def primes(n):
sieve, zeros = range(n), [0]*n
sieve[:2]= 0,0
i = 1
while i*i < n:
if sieve[i]: sieve[i*i:n:i]=zeros[i*i:n:i]
i += 1
return [p for p in sieve if p]

Regards,
Gregor


>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] [Tutor] what? (late nite entertainment) (*)

2005-03-24 Thread Gregor Lingl
What is this? Another version of the well known ...

def what(n):
x,y = range(n), [0]*n
x[1]= 0
z = 0
while z*z <= n:
z+=1
if x[z]: x[z*z:n:z]=y[z*z:n:z]
return [z for z in x if z]

Regards,
Gregor

(*) at least in good old Europe


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] How do I import from __future__ at startup?

2005-02-27 Thread Gregor Lingl
One way to accomplish this is to start Python with
the -Qnew switch:
python -Qnew
If you want to run a script with this option,
e.g. the script division.py with this content:
print 11/3
then use
c:\Python24\python -Qnew division.py
3.67
(or something similar on a Linux system)
Regards, Gregor
Christian Mascher schrieb:
Hello all,
I managed to do this once, but I forgot.
I want division always to be imported from __future__ at startup.
Putting
from __future__ import division
in a file sitecustomize.py doesn't work (which I think is 
counterintuitive). Do I have to use PYTHONSTARTUP variable? Is there any 
way at all?

I searched google and python.org but didn't find a quick answer to this.
Perhaps somebody can help me out?
Thanks,
Christian
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

--
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien
Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27
Autor von "Python für Kids"
Website: python4kids.net
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


[Edu-sig] Do you have a cat?

2005-02-15 Thread Gregor Lingl
If so, have a look at
http://www.linuxjournal.com/article/7403
It shows you how to feed it, using Linux,
Python and an inexpensive microcontroller
Have fun ;-)
Gregor
___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Brainstorming about January

2004-12-12 Thread Gregor Lingl
Kirby Urner schrieb:
OK, ...
===
Math & Programming: From Chaos to Python
Explore topics in mathematics by writing and modifying programs in a
contemporary computer language.
Attention: this is a somewhat technical question/contribution (in 
contrast to the more philosophical ones concerning the design an 
didactics of cs courses)

Hi Kirby and all the others!
In one of my classes I'm just doing similar things. Starting with the 
very first program of John Zelle's  mervelous book I arrived at a 
program  drawing a Feigenbaum diagram.  With  this - and I think with 
all those  chaos/fractal-programs which use  pixel graphics - there  
occurs the problem, that  pixel graphics  with Tkinter  is *very* slow. 
Although I have used a few tricks to make the program fast it still 
needs approximately 50 seconds to draw the diagram (on my machine). 
Moreover it show's that the slow operation is indeed the put-method of 
PhotoImage (and the update method).  My students of course searching the 
net find Feigenbaum applets performing much faster. Being asked about 
that my (somewhat poor) answer is, yes it's slow in Python but the 
advantage is: *you* can write it in Python, whereas you can't write it 
in Java. Not really satisfying.
As this is a problem concerning a large class of applications (at least 
in the context of programming in highschool) I dream of having at hand 
some easily usable class which defines a window for doing fast pixel 
graphics.
As far as I know there are a *lot* of graphics-Toolkits for Python out 
there. Which of them could be used for this task? What are your 
experiences? Do you have significantly faster solutions?

Here is the code of my solution using Tkinter:
# Autor: Gregor Lingl
# Datum: 21. 10. 2004
# feigen.py : zeichnet ein Feigenbaum-Diagramm
from Tkinter import Tk, PhotoImage, Label
WIDTH = 700
HEIGHT = 500
NUM = 2*HEIGHT//3
def f(x):
   return LAMBDA * x * (1-x)
root = Tk()
root.title("Feigenbaum Diagram")
pic = PhotoImage(width=WIDTH+1, height=HEIGHT)
lbl = Label(root, image=pic, bg='white')
lbl.pack()
for i in range(8):
   for j in range(0,HEIGHT):
   pic.put("red", (int(round(WIDTH/7.0)*i),j))
root.update()
for frac in range(WIDTH):
   LAMBDA = 3.3 + frac*0.7/WIDTH
   x = 0.5   # initial value for iteration
   ys={}
   for i in range(150):
   x = f(x)
   for i in range(NUM):
   x = f(x)
   ys[int(HEIGHT*x)]=True
   for y in ys:
   pic.put("black", (frac,y))
   if frac%10==0:root.update()
root.mainloop()
A goal of this class is to help you gain proficiency as a programmer, while
delving into number theory, group theory, chaos and fractals, 

the above program was intended to do just this ...
Another example is from my book "Python für Kids" showing a more regular 
fractal (but suffering froom the same problem ...):

### Python für Kids - Kapitel 12 ###
# Autor: Gregor Lingl
# Datum: 13. 10. 2002
# simplefractal.py : zeichnet ein Sierpinsky-Dreieck
from Tkinter import Tk, PhotoImage, Label
from random import randrange, choice
def mittelpunkt(a,b):
   (x1,y1), (x2,y2) = a, b
   return ( int(round((x1+x2)/2.0)),
int(round((y1+y2)/2.0)) )
def sierpinsky():
   global pixel
   while running:
   for i in range(20):
   ecke = choice(ecken)
   pixel = mittelpunkt(pixel,ecke)
   bild.put('black',pixel)
   root.update()
def start(event):
   print "START"
   global running
   running = 1
   sierpinsky()
def stop(event):
   print "STOP"
   global running
   running = 0
if __name__ == "__main__":
   root = Tk()
   bild = PhotoImage(width=300, height=300)
   lbl = Label(root, image=bild, bg='white')
   lbl.pack()
   root.bind('', start)
   root.bind('', stop)
   ecken = a, b, c = (20,265),(280,265),(150,40)
   pixel = randrange(300), randrange(300)
   for p in (a, b, c, pixel):
   bild.put("black", p)
   root.update()
   root.mainloop()
Any feedback, any suggestions, propositions, solutions are welcome
Regards,
Gregor
P.S.: Some conversations on the list - e. g. the one following the 
posting to which this is a reply - are really difficult to follow for 
me, as I'm not using English as a native language. Sometimes there seems 
to prevail some strange sort of humour or animosity. If that is funny 
for you, that's o.k. but nevertheless I doubt if it's useful for our 
concerns. (I'm well aware of the fact that it might be equally  
difficult for you to understand what I try to say in my rather poor 
English.)

___
Edu-sig mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] explaining functions [Possibly OT]

2004-12-05 Thread Gregor Lingl

Laura Creighton schrieb:
This examples shows beautifully that there are different concepts of 
"function", which
also shows up in Python: some are called to return a result - this *should*
be independent of global circumstances (variables). (Like mathematical 
functions
mentioned in Nicholas' posting.)
The others are functions that *do* something, for instance draw a line 
(like forward
from the turtle graphics module). What forward(50) produces is by no means
independent of the state of the machine. (And it returns None!) So these 
are called
merely because of their side-effects.

And (regrettably?) there are many functions which do both: produce 
side-effects
and return values (in the real world (especially of students)).

And the climax was when I made them fix _each others_ code to make it produce
the correct results.  I was called 'mean' for that.  :-)
 

By all means, what does 'mean' mean in this context?
Gregor
Laura
___
Edu-sig mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/edu-sig
 

___
Edu-sig mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] math fiction

2004-12-03 Thread Gregor Lingl

Kirby Urner schrieb:
...
I just went to the site and looked up
Cryptonomicon as a test.  The site passed with flying colors:
http://math.cofc.edu/faculty/kasman/MATHFICT/mfview.php?callnumber=mf61
 

So it did with Mark Haddons "A curious incident of the Dog in the 
Night-time"
http://math.cofc.edu/faculty/kasman/MATHFICT/mfview.php?callnumber=mf383
a *very rewarding* reading, which we did with a class in a common project
of English- math- physics and cs teachers (in an Austrian highschool).

Gregor
Kirby
___
Edu-sig mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/edu-sig
 

___
Edu-sig mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/edu-sig