Python for children.....

Steve Spicklemire steve at acer.spvi.com
Sun Nov 7 22:28:21 EST 1999


I've also been playing with teaching python to 'children' (well..
middle schoolers anyway... don't tell *them* they are children. ;->)
I've had some luck with my little PyBots toy...  it needs some work,
when I get more time.. but it's enough to teach some simple stuff...

Basically it's a Macromedia Director movie with a single 'cast
member', a circle with a tab. On the mac version the movie imports a
python module (called robots.py) and calls three fuctions over and
over until the user presses the quit button. The functions are:
getX(), getY() and getRot(). They return the horizontal position,
vertical position, and angle of rotation of the ball. With just that
you can teach them if, while, for, functions, object orientation etc..
for a slightly advanced example I came up with this:

----------------------------------------------------------------------

import random

class MovingObject:

    x = 100
    y = 100
    vx = 4
    vy = 4
    omega = 1
    theta = 0

    def getX(self):

        if self.x > 300:
            self.vx = -4 + 2*random.random()
        if self.x < 40:
            self.vx = 4 + 2*random.random()

        self.x = self.x + self.vx
        return self.x


    def getY(self):

        if self.y > 300:
            self.vy = -4 + 2*random.random()
        if self.y < 40:
            self.vy = 4 + 2*random.random()

        self.y = self.y + self.vy

        return self.y

    def getRot(self):
        if self.theta > 360:
            self.omega = -1  + 2*random.random()
        if self.theta < 0:
            self.omega = 1 + 2*random.random()

        self.theta = self.theta + self.omega
        return self.theta

m = MovingObject()

def getX():
    return m.getX()

def getY():
    return m.getY()

def getRot():
    return m.getRot()

if __name__=="__main__":
    print getX()
    print getY()
    print getRot()

                                
Evan Simpson <evan at tokenexchange.com> wrote:

> Now I'm preparing to introduce my children to programming through Python.
> I'm starting with their fascination with Alice, the 3-D animation workshop
> which even my 6 year old enjoys playing with (though he doesn't script it...
> yet).







More information about the Python-list mailing list