[Tutor] my Python learning exercise

Bill Allen wallenpb at gmail.com
Sun Aug 15 01:17:34 CEST 2010


In the process of learning Python, I have given myself a programming
exercise to do.  This is a standard thing I do whenever learning a new
programming language and I have used this same exercise several times before
with other programming languages.  It is a simple text based game that
simply lets a user explore a maze of rooms.   If fully fleshed out, it would
be a Zork or D&D type game.  It demonstrates some basic programming tasks
such as reading data into an array from a file, getting and responding to
user input, looping, control structures, system calls and function
definitions.  I share it here as example code for others also learning
Python and I welcome comments.   The code is for Python 3.x, but the
comments explain how to easily convert it for use in Python 2.x.  It is far
from perfect and is for learning purposes only – something to tinker with.
It is based on concepts from Creating Adventure Games on Your Computer by
Tim Hartnell <http://www.atariarchives.org/adventure/>, which used the BASIC
programming language.   You are welcome to take this code and use and modify
for any purpose you like.  The current version of this code will always be
at this location:
mazegame-current<http://wa5pb.sdf.org/mazegame-current.py>.  You can
create an appropriate data file by making a text file with
contents similar to the following, the current code requires a fixed number
of columns (7 at the time of this writing and subject to change) and an
unlimited number of rows.
0 0 0 0 0 0 0
0 0 4 2 0 0 0
0 0 0 1 3 6 0
0 0 5 0 2 0 0
0 1 0 5 0 0 0
0 3 0 0 4 0 7
0 0 0 0 0 0 2
0 0 0 0 0 5 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100814/40c2a129/attachment.html>


More information about the Tutor mailing list