[Edu-sig] [Fwd: Re: "do" as a keyword]

kirby urner kirby.urner at gmail.com
Wed Dec 12 19:09:59 CET 2007


On Dec 12, 2007 8:54 AM, Christian Mascher <christian.mascher at gmx.de> wrote:

<< SNIP >>

> If Python's main goal was to be "the most beginner friendly programming
> language for the first x hours", then it should probably provide many
> more such constructs; PASCAL FOR-loop is also easier to teach to novices
> than Pythons list iteration on a range()-result.

Python was originally designed for adult professionals with some coding
experience, is not all that beginner friendly in the "never programmed ever"
sense.  Some curricula use toy languages as stepping stones, others
start with Python as maybe the easiest of the real world languages
(because of REPL etc.).

http://xkcd.com/353/

Here's some code for testing a keepmoving() framework, such as Brian
was proposing.  Note my caveat, as well as my use of a generator for
a generic controller (with flagged changing syntax).**

Anyway, enough from my corner.  Back at ya next week!

Kirby

**  http://mail.python.org/pipermail/edu-sig/2007-September/008236.html

# ===== frogger.py =========

"""
Note:  many schools of thought
discourage using global variables
to signal state changes across
functions.  However, understanding
about global variables is critical
so consider this example instructional,
not necessarily a model for production
code.

Kirby Urner
4dsolutions.net
"""

from random import randint

def controller():
    while True:
        someval = randint(0,9)
        print someval # toggle off?
        if someval == 5:
            yield False
        else:
            yield True

handofgod = controller()
untouched = True

def keepmoving():
    global untouched
    untouched = handofgod.next()     # next(handofgod) in 3.x

def main():
    while untouched:
        keepmoving()

def test():
    global untouched

    untouched = True
    main()

    print "====="

    untouched = True
    main()

if __name__ == '__main__':
    test()


More information about the Edu-sig mailing list