Python track: lab 1


Getting started

Go through as much of this python tutorial as you can stand. If this tutorial is too fast-paced or too difficult, consult this page for a list of python tutorials at all levels. This tutorial is also pretty good.

Writing python scripts/programs

Here are some simple python scripts that you should write. Don't forget the magic line:

    #! /usr/bin/env python

in the first line of your file. Make your files executable by typing

    chmod +x <filename>

at the Unix prompt and test them. NOTE: scripts designated [Advanced] are optional but are worth extra credit if your total mark is less than perfect. Also note that in python-speak, the words "script" and "program" mean exactly the same thing. Also also, you won't have to make your scripts executable in this way for any labs other than this one; we cover this here because it's a common way to use python and you should know how it works. You're free to continue to make your later scripts executable if you like, of course. For this lab only, don't put the .py suffix on your program names; for all subsequent labs, do add the .py suffix.

Make sure that scripts that require command-line arguments check these arguments for validity (correct number of arguments and correct types), and output a usage message if the arguments are invalid. See the style guide for more details on how to do this (specifically, this section). This applies to ALL programs you hand in in this track; if you don't do this I'll make you rewrite the offending program(s).

While you're at it, run your completed programs through the style checker to check your code formatting style. If it complains about tabs, see this section of the style guide for advice on how to configure emacs to not output tabs. If you're not using emacs, you're on your own.

Programs to write

That's plenty for this week.