CPSC 111: Introduction to Computing
Notes on Python Programming Style
A goal of CPSC 111 is for you to learn to write programs that are not only correct but also
understandable. These guidelines should help you toward that goal. We ask that you follow these
guidelines when writing programs in this course. They will give you a good basis for developing
a style of your own as you become a more experienced programmer.
This handout includes guidelines for Python constructs that will be covered later in the semester.
Skim these sections now and read them more carefully later when the topics are discussed.
Reasons for a Disciplined Programming Style
Your computer program should be readable, because if it is not readable, the chances of it being
correct are slim. Moreover, if your program is unreadable, it will be difficult and time-
consuming to find and correct the errors in it. Therefore,
The major reason for using a disciplined style of programming is that it will save you time
whenever you have to read your program or debug it.
Your program should be readable by others, not just you. Consider a program you will write in
this course. A grader who has trouble understanding it is not likely to give you good a grade. The
more understandable, the simpler your program appears to a grader, the better the grade they will
be willing to give you.
Outside this course, making programs readable by others becomes even more important. Most
programs live a long time and require "maintenance"; changes to adapt to new and different
requirements, upgrades in other software, new hardware, etc. Further, the author of the program
is quite likely not going to be around when the maintenance is required; someone else must read
the program and understand it enough to update it successfully.
Even the programs you write for yourself should be readable; if not, four weeks after finishing it
you will not remember it enough to make changes simply.
Thus, simply for your own sake and for the sake of others, it makes sense to develop
programming habits that lend themselves to writing readable, understandable, and correct,