small medium large xlarge

Errata for Practical Programming (2nd edition)

By default this page displays the errata for the latest version of the book. If you have a previous version, select it here:

If you've found a new error, please .

• Typo
• Tech. error
• Suggestion
• Maybe next edition
• Not a problem
• Reported in: P1.0 (10-Jun-14)
#76854
PDF page: 1

Would it be possible or desirable to provide the Exercise Solutions in a PDF or some other easily printable form? --David @ Support

• Reported in: B8.0 (21-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52431
PDF page: 11
"For the mathematically inclined, the relationship between // and % comes from this equation, for any two numbers a and b: (b * (a // b) + a % b) is ...more...
• Reported in: P1.0 (17-Oct-13)
• Fixed: 04-Nov-15, awaiting book release
#53034
Paper page: 12
The operator ** for type is not listed under section 2.3. Instead the operator * is listed twice. Wrong: "these operators can be applied to those val...more...
• Reported in: P2.0 (29-May-15)
• Fixed: 04-Nov-15, awaiting book release
#78455
PDF page: 26
Paper page: 12
=> "For example, in type int, the values are …, -3, -2, -1, 0, 1, 2, 3, … and we have seen that these operators can be applied to those values: +, -, ...more...
• Reported in: B8.0 (05-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52586
PDF page: 28
Fourth bullet point - It may be helpful to clarify the second sentence by explaining that the variable will now point to the new value. I find it vag...more...
• Reported in: B8.0 (08-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52594
PDF page: 28
Paper page: 28

"Variables must be assigned values before they can used in expressions." the word "be" is missing

• Reported in: B8.0 (07-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52591
PDF page: 32

"...refers to 10, Python
Python evaluates this expression to -7."

Duplication of the word Python--Dave Pelter

• Reported in: B8.0 (20-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52428
PDF page: 32

end of line 5, beginning of line 6: the word Python is repeated.

• Reported in: B8.0 (24-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52449
PDF page: 51
There are 2 instances where the text in step "4. Description" doesn't match the text in step "5. Body". First, the latter ends with "which are" instea...more...
• Reported in: P1.0 (02-Nov-13)
• Fixed: 04-Nov-15, awaiting book release
#53108
PDF page: 57
"2. Type Contract. The arguments in our function call examples are all inte- gers, and the return values are integers too," The return value is an ...more...
• Reported in: P1.0 (15-Dec-13)
• Fixed: 04-Nov-15, awaiting book release
#53354
Paper page: 59
The first code example of section 3.7 reads: >>> 3 + 5 / abs(-2) 5.5 When I type this into IDLE 3, the return value is 4.0, not 5.5. [ Autho...more...
• Reported in: B8.0 (13-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52377
PDF page: 62
Introduction of "!=" in example: Precondition: n != 0 Not is Index as symbol. Indexed as "Not operator". Defined in text at page 84. I sug...more...
• Reported in: P1.0 (22-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52968
PDF page: 65
Nowhere in the description of strings is it mentioned that a string is a list of characters and that each character can be accessed by its index. I fo...more...
• Reported in: B8.0 (23-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52441
PDF page: 70

line 4 of the text reads: "using the *operator" -- there should be a space after the "*".

• Reported in: B8.0 (23-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52442
PDF page: 71

Lines 4 and 5 explain that single quotes can be used for strings containing double quotes. Then lines 6 and 7 repeat that.

• Reported in: B8.0 (23-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52443
PDF page: 72

Line 10 of the text contains: "Python creates contains a \n sequence" which should read "Python creates contains a \n escape sequence".

• Reported in: B8.0 (23-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52445
PDF page: 76
Line 1 of the text starts: "In an earlier chapter, we explored some built-in functions." For clarity should read "In chapter 3, we explored some built...more...
• Reported in: P1.0 (08-Jul-14)
• Fixed: 16-Oct-15, awaiting book release
#76968
PDF page: 81

"Return True iff x is positive." - note extra 'f' in 'if'.

Author note: iff stands for "if and only if".--Paul Golds

• Reported in: B8.0 (25-Aug-13)
• Fixed: 16-Oct-15, awaiting book release
#52451
PDF page: 85
In the example at the bottom of the page the 5th to last line reads: "Return True iff x is positive." This should be "Return True if x is positive." ...more...
• Reported in: P1.0 (07-Jan-14)
• Fixed: 04-Nov-15, awaiting book release
#76269
PDF page: 85
The sentence 'This is often referred to as or Python decides which string is greater than which by comparing corresponding characters from left to rig...more...
• Reported in: P1.0 (07-Jan-14)
• Fixed: 04-Nov-15, awaiting book release
#76270
PDF page: 88
In the final example shouldn't there be parentheses around the string to be printed? [ Author note: do you mean print(ph, "is basic.")? If so, tha...more...
• Reported in: B8.0 (03-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52568
PDF page: 89
Comparing Strings. The characters in strings are represented by integers: a capital A, for example, is represented by 65, while a space is 32, and a ...more...
• Reported in: B8.0 (28-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52488
PDF page: 90
The section describing the IN operator uses an example meant to illustrate the case sensitivity of the operator. However the example is wrong: >>> ...more...
• Reported in: B8.0 (01-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52554
PDF page: 90
About mid-page, example reports that the phrase, or whatever I should call it, 'A' in 'abc' is True. This violates the case sensitivity of things, and...more...
• Reported in: B8.0 (02-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52560
PDF page: 90

as printed:

>>> 'A' in 'abc'
True

should be:

>>> 'A' in 'abc'
False

• Reported in: B8.0 (06-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52589
PDF page: 90

[...] This is case sensitive:

is:
>>> 'A' in 'abc'
True

should be:
>>> 'A' in 'abc'
False

• Reported in: B8.0 (15-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52931
PDF page: 90
The in operator produces True exactly when the first string appears in the second string. This is case sensitive: >>> 'a' in 'abc' True >>> 'A' in...more...
• Reported in: B8.0 (26-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52469
PDF page: 90

In the second code example on the page:

>>> 'a' in 'abc'
True
>>> 'A' in 'abc'
True

The correct code should be:
>>> 'A' in 'abc'
False

• Reported in: P1.0 (14-Jul-14)
• Fixed: 04-Nov-15, awaiting book release
#77006
Paper page: 91
Throughout the text, chemical compounds that include oxygen (H2O, H2SO4, CO2, etc) are written with a zero instead of a capital letter O. For examp...more...
• Reported in: B8.0 (25-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52452
PDF page: 92
Last line of last example on page reads "print "You should be careful with that!"" which is not valid syntax. It should read: "print("You should be c...more...
• Reported in: P1.0 (29-Oct-13)
• Fixed: 16-Oct-15, awaiting book release
#53084
PDF page: 94

In the docstring "Return True iff x is positive," there's an extra "f"

Author note: iff stands for "if and only if".--Michael Fitzhugh

• Reported in: B8.0 (01-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52556
PDF page: 96
I see that someone has already discussed this, but wouldn't it be better the replace the phrase "This code is the same as this:" with "is e...more...
• Reported in: B8.0 (02-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52561
PDF page: 97

Isn't a colon missing in the first occurrence of "else" in the code at the bottom of the page?--James D Reid

• Reported in: P1.0 (22-Sep-13)
#52967
PDF page: 110
The whole of section 6.3 has an issue where the text refers to module temperature_program, which has 3 doctests, but the screenshots show the outcome ...more...
• Reported in: B8.0 (31-Aug-13)
• Fixed: 04-Nov-15, awaiting book release
#52529
PDF page: 111
The second to last code snippet on the page reads: print("After import, __name__ is", __name__, \ "and echo.__name__ is", echo.__name__) The es...more...
• Reported in: P1.0 (29-Nov-13)
#53229
Paper page: 111
Figure 5 shows the IDLE results of running baking.py, but the text discussing this on page 110 and the start of text on page 111 talks about temperatu...more...
• Reported in: B8.0 (01-Sep-13)
#52545
PDF page: 121

"Here are two more examples, this time using the other two string methods
from the code on page 119."

Should be page 120.

• Reported in: B8.0 (01-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52546
PDF page: 122
The code snippet at the top of the page: >>> help(math.sqrt) Help on built-in function sqrt in module math: should be prefixed by: >>> impor...more...
• Reported in: B8.0 (01-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52552
PDF page: 125

The line:
these three functions to a string with leading and trailing whitespace:

"functions" should be replaced by "methods"

• Reported in: P1.0 (14-Jul-14)
• Fixed: 04-Nov-15, awaiting book release
#77005
Paper page: 126
This is not an error with the text, but an error with the exercise solutions at http: // pragprog (dot) com/wikis/wiki/PracProg2methods. Solutions ...more...
• Reported in: P2.0 (16-Jun-15)
• Fixed: 04-Nov-15, awaiting book release
#78505
PDF page: 133
The bottom figure, the id2:str cell: "none" -> "neon" It should be the result *after* the assignment to nobles[1]. (Author's Note: Actually, the c...more...
• Reported in: P2.0 (16-Jun-15)
• Fixed: 04-Nov-15, awaiting book release
#78506
PDF page: 137
Paragraph 4 - To remove Dpy and Sma, the list useful_markers has to be sliced differently: >>> useful_markers = clelegans_phenotypes[0:4] -> >>> u...more...
• Reported in: P2.0 (16-Jun-15)
• Fixed: 16-Oct-15, awaiting book release
#78507
PDF page: 137

Sorry, my mistake. Only now I read further. Slicing in p.137 is correct.--Silvie Cinkova

• Reported in: P1.0 (23-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52974
PDF page: 140

First paragraph: all references to "celegans_phenotypes" should be "celegan_markers".

• Reported in: B8.0 (05-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52581
PDF page: 146
In the box "Where did my list go?": "As we will discuss in Section 6.3, Testing Your Code Semiautomatically, on page 114" should be: "As we d...more...
• Reported in: P1.0 (26-Sep-13)
#52983
PDF page: 171
Throughout the examples in this chapter newlines are removed using str.strip(). However in the Coursera course in the week 6 files exercise this is ma...more...
• Reported in: P1.0 (22-Nov-13)
#53199
Paper page: 174
(in "The with Statement" section) A misleading oversimplification is given re. the purpose of the 'with' statement in Python: The book states that it...more...
• Reported in: B8.0 (16-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52935
PDF page: 177
In the last paragraph before 10.1: "You’ll first learn how to open and read information from files. After that, you’ll learn about the different te...more...
• Reported in: B8.0 (16-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52936
PDF page: 178

In the penultimate paragraph:

"calendar programs read and process ical files (),"

ical should be iCal and the "()"?

• Reported in: B8.0 (16-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52937
PDF page: 180
First line of second paragraph: "The second statement, contents = example_file.read(), tells Python that you want" should read: "The second s...more...
• Reported in: B8.0 (16-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52938
PDF page: 180
First line of third paragraph reads: "The last statement, example_file.close(), releases all resources associated with" and should be: "The l...more...
• Reported in: P1.0 (18-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52945
PDF page: 180
2nd paragraph. The statements in the text a wrong. they are not the statements in the example. 2nd statement s/b contents = file.read() last statem...more...
• Reported in: P1.0 (19-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52949
PDF page: 183
A call to function sum_number_pairs results in a TypeError. And before that module total needs to be imported. [ Author note: In the paragraph befo...more...
• Reported in: P1.0 (19-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52950
PDF page: 185

In the first paragraph, the line:

"programs using import tsdl, as shown in the next example. This allows us to"

should import time_series

• Reported in: P1.0 (26-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52985
PDF page: 185

The type contract for function definition smallest_value is incorrect as it returns an int.

• Reported in: P1.0 (26-Sep-13)
#52984
PDF page: 186

In function definition smallest_value_skip there is no check for a '-' in the first data line after the header.

• Reported in: P1.0 (26-Sep-13)
• Fixed: 04-Nov-15, awaiting book release
#52986
PDF page: 186

The type contract for function definition smallest_value_skip is incorrect as it returns an int.

• Reported in: B8.0 (17-Sep-13)
#52942
PDF page: 187

Section 10.4: all references to "urllib.urlrequest" are incorrect. The correct module name is "urllib.request".

• Reported in: P1.0 (19-Sep-13)
#52951
PDF page: 189
Top of page: "We now face the same choice as with skip_header: we can put find_largest in a module (possibly tsdl)," The module name is "time_serie...more...
• Reported in: P1.0 (19-Sep-13)
#52952
PDF page: 190
First paragraph: "here is the same code without using tsdl.skip_header and find_largest as helper methods:" should be "time_series.skip_header". Th...more...
• Reported in: P1.0 (19-Sep-13)
#52953
PDF page: 193

In example at the top of the page, file "multimol.pdb" is not closed.

• Reported in: P1.0 (26-Sep-13)
#52987
PDF page: 196
Not so much an error as a redundant check in function definition read_molecule: if fields[0] == 'ATOM': is redundant as with the format of the d...more...
• Reported in: P1.0 (05-Feb-14)
#76373
Paper page: 213

"key/value pair listed is 'canada goose': 71" should be,
"key/value pair listed is 'canada goose': 183"--Azef Aziz

• Reported in: P1.0 (12-Mar-14)
#76531
PDF page: 219
It's most likely my error but when I run the first code under 11.3, "Storing Data Using Dictionaries", the bird_counts[] list never populates. I ran ...more...
• Reported in: P1.0 (11-Feb-14)
#76399
PDF page: 220
This is not an error in the book, but for the explanation of exercise 5 on page 220 (Storing Data Using Other Collection Types). For the return, yo...more...
• Reported in: P1.0 (31-Oct-13)
#53095
PDF page: 224
At the bottom of the page: def find_two_smallest(L): """ (list of float) -> tuple of (int, int) The type of the list in int not float. This e...more...
• Reported in: P1.0 (30-Oct-13)
#53090
PDF page: 225

In "Find, Remove, Find" it is not the re-insertion that is the problem, but the removal, as min2 is obtained before the re-insertion.

• Reported in: P1.0 (31-Oct-13)
#53096
PDF page: 230
Last example on page: # Examine each value in the list in order for i in range(2, len(values)): should be: # Examine each value in the list in o...more...
• Reported in: P1.0 (28-Jan-14)
#76346
PDF page: 233
sea_level_press = [] sea_level_press_file = open('darwin.slp', 'r') for line in sea_level_press_file: sea_level_press.append(float(...more...
• Reported in: P1.0 (31-Oct-13)
#53097
PDF page: 233

In function definition:
def time_find_two_smallest(find_func, lst): the return statement has a period at the end of the statement.

• Reported in: P1.0 (31-Oct-13)
#53098
PDF page: 233

In the example on the page the file is opened for reading but never closed.

• Reported in: P1.0 (13-Nov-13)
#53145
PDF page: 239
Bottom of page: list[0:i] doesn't contain value, and 0 <= i <= len(lst) should be: list[0:i] doesn't contain value, and 0 <= i < len(lst) ...more...
• Reported in: P1.0 (29-Nov-13)
#53230
Paper page: 241
In the explanation of the function linear_search(), it says, "At the end, we return... len(list) if value wasn't in list.", but actually -1 is returne...more...
• Reported in: P1.0 (13-Nov-13)
#53147
PDF page: 243

function definition "time_it" has the type contract:

(function, object, list) -> number

which should be:

(function, list, object) -> number

• Reported in: P1.0 (08-Feb-14)
#76390
Paper page: 246

" while if it is greater than j, we should move j down." should be (i think), "while if it is greater than v, we should move j down."--Asif Aziz

• Reported in: P1.0 (09-Feb-14)
#76392
Paper page: 246

'because L[i] isn't included in the range; instead...' should be (i think), 'because L[m] isn't included in the range....'--Asif Aziz

• Reported in: P1.0 (09-Feb-14)
#76393
Paper page: 248
code related to binary search, if __name__ == '__main__': import doctest doctest.testmod() will not display output unless dockets.testm...more...
• Reported in: P1.0 (09-Jul-14)
#76975
PDF page: 257

Figure 13—First few steps in selection sort
=>
Figure 13—First few steps in insertion sort

• Reported in: P1.0 (14-Nov-13)
#53151
PDF page: 260

The doctest for function definition bin_sort is incorrect as the function returns a sorted copy of the list.

• Reported in: P2.0 (20-Jan-15)
• Fixed: 04-Nov-15, awaiting book release
#78067
PDF page: 282
In the example at the bottom of the page, the ISBN of book_1 and book_2 are the same, so '==' cannot distinguish between them. Assume this has been r...more...
• Reported in: P2.0 (21-Jan-15)
• Fixed: 04-Nov-15, awaiting book release
#78069
PDF page: 282

Previous submit not error, Sorry!--Eugene Rodriguez

• Reported in: P1.0 (30-Nov-13)
#53250
PDF page: 287

The example method at the bottom of the page:

def __str__(self):
""" (Member) -> str

The type contract should be:

""" (Faculty) -> str

• Reported in: P1.0 (19-Jul-14)
• Fixed: 04-Nov-15, awaiting book release
#77023
PDF page: 287
Variable paul = Faculty('Paul', 'Ajax', 'pgries@cs.toronto.edu', '1234') contains only string 'Paul', not 'Paul Gries' as suggested by the print(paul)...more...
• Reported in: P1.0 (30-Nov-13)
• Fixed: 04-Nov-15, awaiting book release
#53251
PDF page: 291
End of first paragraph reads: rewritten to return a Molecule object instead of a list of tuples: should be: rewritten to return a Molecule ob...more...
• Reported in: P2.0 (24-Aug-15)
• Fixed: 04-Nov-15, awaiting book release
#78779
PDF page: 295
Paper page: 287
In both of the __str__ functions defined on this page, a string with new lines between each piece of data is returned. However, the docstring shows t...more...
• Reported in: P1.0 (05-Nov-13)
• Fixed: 04-Nov-15, awaiting book release
#53114
PDF page: 302
The test case pattern at the top of the page: been expected = «the value we expect will be returned» What is the "been" on the first li...more...
• Reported in: P1.0 (05-Nov-13)
• Fixed: 04-Nov-15, awaiting book release
#53115
PDF page: 304
Last paragraph on page: Following those steps, we created a variable, nums The variable in the docstring is "L" not nums". This error occurs thr...more...
• Reported in: P1.0 (04-Dec-13)
• Fixed: 04-Nov-15, awaiting book release
#53275
PDF page: 328
First sentence of "Changing Colors": Almost all foreground colors can be set using the bg and fg keyword arguments, respectively. Should be: ...more...
• Reported in: P1.0 (04-Dec-13)
• Fixed: 04-Nov-15, awaiting book release
#53276
PDF page: 335
Last sentence before the code: accessed using self.state, and its controllers are the methods upClick and quitClick. the 2 method names are: ...more...
• Reported in: P1.0 (06-Dec-13)
• Fixed: 04-Nov-15, awaiting book release
#53292
PDF page: 337
Question 5 states: In Section 3.4, Using Local Variables for Temporary Storage, on page 39, should be: In Section 3.3, Defining Our Own Funct...more...
• Reported in: P2.0 (04-Mar-15)
• Fixed: 03-Nov-15, awaiting book release
#78226
PDF page: 338
Dear Sir I have bought the PDF file (practical programming_p2_0.pdf) last month. Unfortunately there is no page "338" in my PDF data! Is there any mi...more...
• Reported in: P1.0 (01-Dec-13)
• Fixed: 03-Nov-15, awaiting book release
#53258
PDF page: 343
The first line on the page: The Python equivalent is a type we haven’t seen before called bytes... This is incorrect. We were introduced to byte...more...
• Reported in: P1.0 (19-Feb-14)
• Fixed: 03-Nov-15, awaiting book release
#76440
Paper page: 350
for c in countries: cur.exec('INSERT INTO PopByCountry VALUES (?, ?, ?)', (c[0], c[1], c[2])) can be simply presented as, cur.ex...more...
• Reported in: P1.0 (02-Dec-13)
#53264
PDF page: 360
Nowhere in this chapter are there instructions to close the connection to the database when you're finished working with it: con.close() Had to ...more...
• Reported in: P1.0 (07-Feb-14)
#76383
PDF page: 371
Paper page: 367
In the index for "backslash", only the meaning of backslash in Windows directory paths is listed (P.174). The use of backslash as line-continuation (...more...