Python 4ed Errata
Page xvi: Susan's name is spelled Schwartz, not Schwarz.
Pg xxiv: Last Sentence – “Together, they Mark and Barbara are…” – delete the they or their names or add commas around their names – also missing a period at the end of the sentence
Page 40-41:
Problems 2.9 and 2.12 are exactly the same problem.
Problem 2.27 continues on the next page and it is not obvious to turn the page
Page 48, last paragraph before the example code: The last sentence does not seem to have been completed (“The order of the strings we give”).
- David Largent, Instructor of Computer Science, Ball State University
Page 46:
The following text should be formatted with a green background as part of the code output of the print 4 + "5" command. Instead, it has white background text and looks like explanatory text at first glance.
Inappropriate argument type. An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.
(Guzdial 46)
Guzdial, Mark J. Introduction to Computing and Programming in Python, 4th Edition. Pearson, 20150318. VitalBook file. – Aaron Curtis, BYUH
Page 49:
The program should be:
def mathWithStrings():
mystring = "My name is Inigo Montoya."
mythreat = 'You killed my father. Prepare to die.'
print mystring + mythreat #String concatenation
print (mystring + mythreat ) * 6
Page 52:
not is introduced but not explained (it is explained on pg 431 later in the text)
Page 56:
The reverse code was duplicated. The mirror code is:
def mirror(source):
pile = ""
for letter in source:
pile = letter+pile+letter
print pile
Page 65:
Paragraph above Program 33 – in the last line, it should read “…where to expect…”
Page 68:
The Chapter Summary does not include new concepts: .lower (on pg 53), .upper (on pg 53), not (on pg 52), len (pg 58), % (on pg 61), == (on pg 61) – these would be helpful as review
Page 72
The output in the last line of question 3.16 on p. 72 is missing the spacing between the letters.
Page 122:
The index entry for “grayScaleNew” is p. 122.
I suspect this is the first time the word actually appears as part of the text.
The index should also include p. 103…the reader is probably looking for Program 43.
Page 140:
Second sentence at the top of p. 140: If the luminance is low, we make the pixel BLACK.
Page 141:
In question 5.1, the function discussed in the question is named "changeColor", however in the third bullet point, it suddenly is named "changeRed". (This is extra confusing, as the colour being changed in this part of the problem is actually blue.)
I would also suggest that problem 5.2 could do with some general re-wording when the next edition comes – the way the third sentence is constructed "these changes" is confusing, as the changes have not yet been discussed.
Page 148, end of first paragraph: Inside of the parentheses… 630 should be 639
- David Largent, Instructor of Computer Science, Ball State University
Page 173:
6.3.6 – second line in the paragraph – this section will rotate the horse, not Barb.
Page 182:
Program 85 introduces the JES function duplicatePicture but it is not included in the Programming Summary at the end of Chapter 6
Page 184:
In the first paragraph of Section 6.5, the (e.g.) gives an example about background subtraction that is now in Chapter 5, not Chapter 6.
Page 360: The bottom of Figure 13.1 should be </html>, not <html>
Page 240: From Andre: The call to the normalize function has been removed in Program 102. But, the its description remains in the “How it works” section below the code…
From 242: From Andre: Program 104 returns a sound file which only contains “united people”, not the preamble “We the united people of the United States”.
Also, the warning in the first line of Program 104 is no longer needed…there is no variable called file.
I screwed up and copied the wrong version into the chapter. Here's the right version.
def splicePreamble2():
file = "preamble10.wav"
source = makeSound(file)
# This will be the newly spliced sound
target = makeSound(file)
# targetIndex starts at just after
# "We the" in the new sound
targetIndex=17408
# Where the word "United" is in the sound
for sourceIndex in range(33414, 40052):
value = getSampleValueAt(source, sourceIndex)
setSampleValueAt(target, targetIndex, value)
targetIndex = targetIndex + 1
# Where the word "People" is in the sound
for sourceIndex in range(17408, 26726):
value = getSampleValueAt(source, sourceIndex)
setSampleValueAt(target, targetIndex, value)
targetIndex = targetIndex + 1
#Stick some quiet space after that
for index in range(0,1000):
setSampleValueAt(target, targetIndex,0)
targetIndex = targetIndex + 1
#Let's hear and return the result
play(target)
return target
Page 258, Program 111: I think “s1” should be “s2” in the last three lines of the program. Alternatively, if “s2” really is right, there is no need to return “s1”, since it is an input parameter.
- David Largent, Instructor of Computer Science, Ball State University
Page 259: (I'm not sure that this is an error yet, but I'll include Andre's comment)
Program 112: The for loop should start at the end of the file. Also, when it ends at sample 0, value2 accesses the sample at –delay which is near the end of the file. I believe the for loop should be: for index in range(len(soundSamples)-1,delay,-1):
Programs 112 & 113: To be consistent with Program 111, you might want to multiply value2 by 0.6?
Page 260, Program 114: Should the range of the “for” statement start at zero, rather than one? I guess it depends on what the intent of the functionality of the “num” input parameter is. As written, if “num” has a value of one, it will return an empty sound. If “num” has a value of two, it will return a sound with the original sound, plus one echo. It seems more intuitive to me for a value of one to mean sound plus one echo, and a value of two to mean sound plus two echoes. And in fact, the “s2” sound variable is sized to accommodate this.
- David Largent, Instructor of Computer Science, Ball State University
Page 323, Program 135, line 5: I believe what is printed is two “single quotes”, but it looks like one “double quote”. This needs to be explicitly stated to avoid the confusion. Alternatively, I suggest simply changing it to two “double quotes”.
Page 323, Program 135, line 6: Remove the semi colon at the end of the statement.
Page 323, Common Bug section: In the title, “getMediatPath” should be “getMediaPath”.
- David Largent, Instructor of Computer Science, Ball State University
Page 357: Program 150 crashes when run with test.wav. The problem is with the test for the break. The line
if soundIndex > getLength(sound):
should be replaced with
if soundIndex == getLength(sound):
Figure 12.4 has been rotated. The color should be at the top, not on the left edge. (Try doing an explore on the output from soundToPicture.)
I'm writing about program 147, on p367 of the Python 4ed global edition; I suspect the page numbers aren't the same in the US edition.
The program nicely introduces try/except to handle data that would otherwise cause a crash. When I looked at the data to see what was causing the problem, I found that China has THOUSANDS of executions, and felt it was a little rude to report Saudi Arabia as the maximum with 423, so I decided to replace the 'pass' in 'except' with something to capture that. That's when I discovered the other problems.
The csv contains some numbers with commas in them; of course they don't convert to integer, so they're just being skipped, but they're necessarily bigger than 423.
When we fix that, the new maximum is, not surprisingly, the final row, which sums all the other rows. So we need to exclude that row.
We also need to accept that the empty cell should probably be counted as zero.
Finally we get to a function that reports:
The highest-executing country was IRAN, with 1663 executions
(unless it was CHINA, with THOUSANDS executions)
Unfortunately, this makes the function rather more complicated that was intended, so I'm not suggesting replacing it in the book, but this might be a useful addition to the errata site.
def highestExecutions2():
# Program 147 from Guzdial & Ericson, adapted to deal better with exceptional data
file = open(getMediaPath("DeathPenalties.csv"))
csvfile = reader(file) # Using the read() function from the csv module
max = -1
altmax = ""
maxCountry = "None"
altmaxCountry = ""
for row in csvfile:
try:
country = row[0]
countStr = row[14].replace(",", "") # Still a string at this point; remove any commas
if countStr == "": # Allow for empty cells
executions = 0
else:
executions = int(countStr)
if executions > max and country.find("TOTALS") < 0: # We don't want to compare the total
max = executions
maxCountry = country
except: # If we get here, the value in row[14] couldn't be converted to an integer
altmax = row[14] # Record the value as a string, and its country
altmaxCountry = row[0]
print("The highest-executing country was " + maxCountry + ", with " + str(max) + " executions")
if altmax <> "": # If we found any non-blank non-integer values, report the most recent one we found
print("(unless it was " + altmaxCountry + ", with " + altmax + " executions)")
Simon
School of Electrical Engineering and Computing
University of Newcastle