Python for younger children

Jeff jam at quark.emich.edu
Tue Sep 21 13:35:56 EDT 1999


On Tue, Sep 21, 1999 at 04:41:53PM +1000, Stuart Hungerford wrote:
> John Leach wrote:
> 
> > I have two children 9 and 11 and I'd like them to learn
> > Python because they don't learn programming at school and I
> > feel that it's something they should be learning at that age
> > - and they're keen to do so.
> 
> I'd be interested to hear your experiences, my 10 and 8 year old are keen
> to learn as well.  I've downloaded Alice (see www.alice.org) which uses
> Python to manipulate 3D graphics objects, but I'm sure there must be a
> simpler approach.
> 
> Stu
> 

I'm in a similar position-- I sometimes watch an eight year old (2nd
grader), and he is primarily interested in 'helping' and having fun helping
me program (aka 'work'). I started with just running the interpreter from
the linux prompt, and letting him type simple expressions on the keyboard--
like '1>2' and '1<2', to show some simple logic operators (and the concept
of '1 is true, 0 is false'). by this point, he had built up the confidence
to type simple math problems into the 'prompt', and get immediate results,
like '100+10' and '23456*2', etc.. basically just letting him 'play' with
the keyboard and try to get familiar with it, by putting in things he knew
the answer to, and verifying that the computer spit out the 'right'
response. then, a little later, he suggested that we write a program (he
already understands that I can type *far* quicker than he can, so he "lets"
me do the hard work of typing on the keyboard), and immediately settled down
to write out what he wanted on paper, which amounted to a simple number
guessing game. it started as a simple 'pick a number, tell me when it's
right'. so far, we've added the 'number_of_guesses' thing, and I'm sure more
features (like a high score list) will be added soon. the code we have so
far is attached. it's quite rough (which was part of the point-- he doesn't
care about lots of documentation and 'clean' code ;)), but it works. I'm
hoping others will find it useful as well. please send along patches,
flames, comments, etc.

regards,
J
-- 
|| visit gfd <http://quark.newimage.com/> 
|| psa member #293 <http://www.python.org/> 
|| New Image Systems & Services, Inc. <http://www.newimage.com/>
-------------- next part --------------
#!/usr/bin/env python

import readline
import time
import whrandom

_UPPER = 200

x = whrandom.randint(1, _UPPER)
print x

number_of_guesses = 0

while 1:
	number_of_guesses = number_of_guesses + 1
	print
	print "I picked a number between 1 and %d." % (_UPPER)
	guess = raw_input("what is your guess? ")
	guess = int(guess)
	if guess == x:
		print
		print "*** that's it! you win! ***"
		if number_of_guesses == 1:
			print "you took *ONE* try and got it right!"
		else:
			print "you took %d tries." % (number_of_guesses)
		print
		x = whrandom.randint(1, _UPPER)
		print x
		print
		print
		number_of_guesses = 0
 	elif guess > x:
		print
		print "my number is less than %d" % (guess)
		print
	elif guess < x:
		print
		print "my number is greater than %d" % (guess)
		print
	print


More information about the Python-list mailing list