Hardware Reference
In-Depth Information
does what you want it to. Better code is code that does this in a concise, easy-to-understand
way. After that you get some code that is more memory eicient, some that is more eicient
in the number of code lines it uses and others that execute faster. Do not get bogged down by
this; code that takes a 0.25 second to run between user inputs is totally indistinguishable
from code that takes 0.25uS to run. However, context is everything, so code that takes 25
seconds to run will win a lot less friends than 0.25 second code.
Making a Start
In the preceding chapter, “Introductory Software Project: he Insult Generator”, you can see how
you could make a list of words, such as nouns and verbs, for the insult generator. Lists are very
useful, and you will use them many times in programming. In this chapter you will use a list to
represent the tic-tac-toe playing board. Each position in the list represents a square, and the
contents of each position represents the contents of the square. his is shown in Figure 3-1.
Figure 3-1:
he relationship
of the board to
the list.
So the irst thing you need to do is write a function that will print out the board on the
Python text console. his is the sort of thing that was done before the widespread use of
graphics windows, and is a lot simpler to cope with. Basically, you need to output each square
Search WWH ::




Custom Search