Operation Manual
Experiments in Python
88
Notes:
The next bit of information that the player needs is how many letters were in their
guess but not in the correct places. Since we don’t care about the position, we are
just counting letters. For each possible letter, we count how many are in the secret
and how many are in the guess. This will include those that are in the correct
position too, but we’ll get rid of those counts in a minute. We also only want the
minimum number since we are only counting those in the guess that are also in
the secret. By adding up all these counts, and subtracting those that were correct,
we have the number of letters that were in the wrong places.
This gives the player the clues they need to guess the answer.
This example is quite difficult but it is the ability to follow and understand this
kind of program that will help you become a great programmer. The ability to
create a logical process to solve a problem will help you on your journey to be a
computing specialist.
Comments (# and """)
In the code, you will see the “#” character before some line of
English. The “#” character starts a “comment” in the code. That
is, everything that comes after the “#” is ignored by the computer.
Python programmers use “#” to write little notes to themselves
and anyone reading the code.
The art of writing useful comments is extremely important and a
skill you should learn if you want to be a good programmer. After
you have written a few programs without comments, left them for
a month and then returned to them, you’ll understand the value of
good comments.
Comments can also be put inside a pair of triple quotes: """. You
will see this in some of the listings. These comments, when placed
at the start of a module, function or class, are known as
“docstrings”, which another computer program (PyDoc) can
gather together to create a “user guide” to your program.