Errata, First Printing


CHAPTER 1

p. xiii

Printed: ...we refer to "Python" after "programming in the title...
Fixed: ...we refer to "Python" after "programming" in the title...
Reported by Porter Scobey 4-Jan-2016.

p. 4, box at bottom

Printed: The lingua france in this book is Python 3.
Fixed: The lingua franca in this book is Python 3.
Reported by Porter Scobey 4-Jan-2016.

p. 16, line 9

Printed: ...variable whose associated a data-type value does not change during the execution...
Fixed: ...variable whose associated data-type value does not change during the execution...
Reported by Ivy Gu Zhong 3-Jun-2016.

p. 17, "Assignment Statements" paragraph

Printed: The left side of an assignment statement must be a single variable.
Fixed: For now, the left side of an assignment statement must be a single variable; Section 3.3 elaborates.
Reported by Marcus Dicanter 1-Aug-2017.

p. 24, second paragraph

Printed: ...often in conjunction with the str() function...
Fixed: ...often in conjunction with the str() function...
Reported by Diego Sejas Viscarra 15-May-2017.

p. 28, Typical float expressions table

Printed: To be consistent with the associated text 6.02e23 should be 6.022e23, in two places.
Reported by Diego Sejas Viscarra 22-Jan-2018.

p. 33, caption of table at top

Printed: Truth-table proof that a and !(not a or not b) are identical.
Fixed: Truth-table proof that a and not(not a or not b) are identical.
Reported by Porter Scobey 4-Jan-2016.

p. 34, "Typical comparison expressions" insert

Printed: (b*b - 4.0*a*c) >= 0
Fixed: (b*b - 4.0*c) >= 0
Reported by Diego Sejas Viscarra 21-May-2017.

p. 34, last full paragraph

Printed: ...and the comparison expression (year % 400) != 0) only if the year is divisible by 100.
Fixed: ...and the comparison expression (year % 400) == 0) only if the year is divisible by 100.
Reported by Diego Sejas Viscarra 15-May-2017.

p. 38, Abbreviation alert

Printed: The function call sqrt(16.0) returns 4.0
Fixed: The function call math.sqrt(16.0) returns 4.0
Reported by Diego Sejas Viscarra 15-May-2017.

p. 41

Printed: In a famous incident in 1985, a French rocket...
Fixed: In a famous incident in 1996, a French rocket...
Reported by Jean-Paul Forest 30-Oct-2017.

p. 45, first line

Printed: ...so you can use them systems...
Fixed: ...so you can use them in systems...
Reported by Diego Sejas Viscarra 21-May-2017.

p. 53, Exercise 1.2.22

Printed: w = 35.74 + 0.6215 T + (0.4275 T) - 35.75)v0.16
Fixed: w = 35.74 + 0.6215 t + (0.4275 t) - 35.75)v0.16
Reported by Diego Sejas Viscarra 14-Nov-2017.

p. 53, Exercise 1.2.24

Printed: ... generated by the Math.random() method.
Fixed: ... generated by the random.random() function.
Reported by Diego Sejas Viscarra 29-Jun-2016.

p. 57

Printed:
if x >= 0:
   stdout.write('not ')
stdout.writeln('negative')
Fixed:
if x >= 0:
   stdio.write('not ')
stdio.writeln('negative')
Reported by Diego Sejas Viscarra 29-Jun-2016.

p. 57

Printed:
if x >= 0:
   stdout.write('not ')
   stdout.writeln('negative')
Fixed:
if x >= 0:
   stdio.write('not ')
   stdio.writeln('negative')
Reported by Diego Sejas Viscarra 29-Jun-2016.

p. 58

Printed: stdio.writeln('Remainder = ' + num % den)
Fixed: stdio.writeln('Remainder = ' + str(num % den))
Reported by Philip Ai, 2-Oct-2015.

p. 58, "Typical examples of using if statements" insert

Printed: discriminant = b*b - 4.0*a*c
Fixed: discriminant = b*b - 4.0*c
Reported by Diego Sejas Viscarra 21-May-2017.

p. 60, Flowchart example (while statement)

Printed: stdio.writelnln(str(i) + 'th Hello')
Fixed: stdio.writeln(str(i) + 'th Hello')
Reported by Diego Sejas Viscarra 29-Jun-2016.

p. 61, Anatomy of a while loop

Printed: stdio.writelnln(str(i) + 'th Hello')
Fixed: stdio.writeln(str(i) + 'th Hello')
Reported by Chris Hendriks 03-Mar-2018.

p. 63, first paragraph

Printed: If i is 4 before the statement executed...
Fixed: If i is 4 before the statement executes...
Reported by Diego Sejas Viscarra 14-Nov-2017.

p. 64, Description of powersoftwo.py

Printed: ...the first n powers of 2.
Fixed: ...the first n+1 powers of 2.
Reported by anonymous 14-May-2017.

p. 64, Description of powersoftwo.py

Printed: ...the program write n + 1 lines.
Fixed: ...the program writes n + 1 lines.
Reported by Diego Sejas Viscarra 03-Jul-2016.

p. 69, Flowchart for divisorpattern.py, in the leftmost box

Printed:
stdio.writeln('  ')
Fixed:
stdio.writeln('* ')
Reported by Diego Sejas Viscarra 03-Jul-2016.

p. 71

Printed: if income < 0.0:
Fixed: if income < 0:
Reported by Diego Sejas Viscarra 14-Nov-2017.

p. 71

In the code template defining "else if" clauses, "block of statements" should be italicized.
Reported by Diego Sejas Viscarra, 14-Nov-2017.

p. 75, Box describing variables

Printed: t: estimate of c
Fixed: t: estimate of square root of c
Reported by Diego Sejas Viscarra 22-April-2017.

p. 77

Printed: % python binary.py 512
100000000
Fixed: % python binary.py 512
1000000000
Reported by Huub Everaert, 22-Feb-2016.

p. 81

Printed: ...each iteration of the outer for loop...
Fixed: ...each iteration of the outer while loop...
Reported by Diego Sejas Viscarra 03-Jul-2016.

p. 82, first paragraph

Printed: ... the while loop will do its job and the invariant will continue to hold.
Fixed: ... the inner while loop will do its job and the invariant will continue to hold.
Reported by Diego Sejas Viscarra 22-April-2017.

p. 83

Printed: x = 1.0 + 2.0*random.random()
y = 1.0 + 2.0*random.random(
Fixed: x = -1.0 + 2.0*random.random()
y = -1.0 + 2.0*random.random()
Reported by Salman Ahmad, 25-Oct-2015 and Diego Sejas Viscarra 22-April-2017.

p. 83, last paragraph

Printed: First, suppose that such a loop calls stdout.writeln().
Fixed: First, suppose that such a loop calls stdio.writeln().
Reported by Diego Sejas Viscarra 03-Jul-2016.

p. 84, first (partial) paragraph

Printed: ...on an infinite loop of stdout.writeln() calls...
Fixed: ...on an infinite loop of stdio.writeln() calls...
Reported by Diego Sejas Viscarra 03-Jul-2016.

p. 84, first full paragraph

Printed: One way to locate such a bug is to insert calls of stdout.writeln() to produce a trace.
Fixed: One way to locate such a bug is to insert calls of stdio.writeln() to produce a trace.
Reported by Diego Sejas Viscarra 03-Jul-2016.

p. 84, "An infinite loop (with output)" insert

The output of the program is incorrect. It should not contain "1st Hello", "2nd Hello", or "3rd Hello", and should begin with "4th Hello".
Reported by Diego Sejas Viscarra 14-Nov-2017.

p. 90, Exercise 1.3.10

Printed: for n = 2, 4, 8, 16, 32, 64, ..., 2048
Fixed: for n = 2, 4, 8, 16, 32, 64, 128
Reported by Joseph Cunningham, 28-Sep-2021.

p. 90, Exercise 1.3.11

Printed: n /= 10
Fixed: n //= 10
Reported by Bob Dondero, 15-Jun-2015.

p. 91, Exercise 1.3.13

Printed: Your program should write nothing if n is negative"
Fixed: Your program should write nothing if n is negative or zero"
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 92, Exercise 1.3.19

Printed: Modify binary.py...
Fixed: Modify binary.py (Program 1.3.7)...
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 92, Exercise 1.3.20

Printed: v /= 2
Fixed: v //= 2
Reported by Bob Dondero, 15-Jun-2015.

p. 92, Exercise 1.3.20

Printed: ...into a String s
Fixed: ...into a string s
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 93, Exercise 1.3.21

Printed: Compose a version of gambler.py...
Fixed: Compose a version of gambler.py (Program 1.3.8)...
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 93, Exercise 1.3.25

Printed: Modify factors.py...
Fixed: Modify factors.py (Program 1.3.9)...
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 93, Exercise 1.3.26

Printed: ...using the termination condition (i < n) instead of (i*i <= n) in factors.py...
Fixed: ...using the termination condition (factor < n) instead of (factor*factor <= n) in factors.py...
Reported by Chris Hendriks, 24-Mar-2018.

p. 94, Exercise 1.3.31

Printed: ... b to 2 * sqrt(1 - sqr(x) - sqr(y))
Fixed: ... b to 2 * y * sqrt(1 - sqr(x) - sqr(y))
Reported by Diego Sejas Viscarra, 31-May-2018.

p. 95, Exercise 1.3.33

Printed: The checksum digit d[i]...
Fixed: The checksum digit d[1]...
Reported by Diego Sejas Viscarra, 31-May-2018.

p. 96, Exercise 1.3.37 solution

Printed: To compute 3x, we nest this for loop within another for loop
Fixed: To compute 3x, we nest this for loop within a while loop
Reported by Diego Sejas Viscarra, 31-May-2018.

p. 97, Exercise 1.3.39

Printed: ...the direct method with nested for loops, the improvement with a single while loop, and the latter with the termination condition (term > 0).
Fixed: ...the direct method with nested loops, the improvement with a single loop, and the latter with the loop continuation condition (term > 0).
Reported by Diego Sejas Viscarra, 4-Aug-2018.

p. 101

Printed: y = [0.40, 0.10, 0.50]
Fixed: y = [0.50, 0.10, 0.40]
Reported by Diego Sejas Viscarra, 21-Jan-2018.

p. 101

The suits array is constant, and so really should be named SUITS (4 places).
Reported by Diego Sejas Viscarra, 01-Mar-2018, and Chris Hendriks, 30-Mar-2018.

p. 101

Printed: ...y[2] refers to .50...
Fixed: ...y[2] refers to .40...
Reported by Chris Hendriks, 30-Mar-2018.

p. 102, first code fragment

Printed: for i in range(n)
Fixed: for i in range(n):
Reported by Huub Everaert, 2-Mar-2016.

p. 102, second code fragment

Printed: for i in range(n)
Fixed: for i in range(n):
Reported by Huub Everaert, 2-Mar-2016.

p. 103, Memory representation paragraph

Printed: Accessing a reference to element i of an array...
Fixed: Accessing element i of an array...
Reported by Diego Sejas Viscarra, 14-Nov-2017.

p. 103, Memory representation paragraph

Printed: ...Python generates code that adds the index i to the memory address of the first element of the array.
Fixed: ...Python generates code that adds the index i to the memory address that references the address of the first element of the array.
Reported by Diego Sejas Viscarra, 4-Feb-2018.

p. 104

Printed: In the "Informal trace for reversing an array," in the row for the 3rd iteration of i, the number between 5 and 4 is 3.
Fixed: That number should be 1.
Reported by Amir Mahallati, 1-March-2016.

p. 105, second paragraph

Printed: in an array in a[]
Fixed: in an array a[]
Reported by Diego Sejas Viscarra, 14-nov-2017.

p. 105, first code fragment

Printed: for i in range(len(a))
Fixed: for i in range(len(a)):
Reported by Huub Everaert, 2-Mar-2016.

p. 110, table

Printed: assign v to each of the elements in a[]
Fixed: assign to v each of the elements in a[]
Reported by Diego Sejas Viscarra, 14-Nov-2017.

p. 111, last paragraph

Printed: ...the values a[i] and a[j] are found...
Fixed: ...the values deck[i] and deck[j] are found...
Reported by Diego Sejas Viscarra, 14-Nov-2017.

p. 112, "Sampling without replacement paragraph

Printed: ...each element in set...
Fixed: ...each element in the set...
Reported by Chris Hendriks, 30-Mar-2018.

p. 113, sample.py code listing

Printed: # Create a random sample of size m in perm[0..m).
Fixed: # Create a random sample of size m in perm[0:m].
Reported by Diego Sejas Viscarra, 4-Feb-2018.

p. 116, table

The columns entitled "count" and "collectedCount" should be switched.
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 116, table

The column entitled "val" instead should be entitled "value".
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 118

Printed: The program uses an array isPrime[] of n booleans...
Fixed: The program uses an array isPrime[] of n+1 booleans...
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 120

Printed: When the nested for loop ends...
Fixed: When the nested for loops end...
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 122

Printed: ...the array [[18, 19, 20], [21 22, 23]]...
Fixed: ..the array [[18, 19, 20], [21, 22, 23]]...
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 123, Typical spreadsheet calculations

Printed: a[i][n] = total / m
Fixed: a[i][n] = total / n
Reported by Philip Ai, 15-Oct-2015.

p. 123, Typical spreadsheet calculations

Printed: a[m][j] = total / n
Fixed: a[m][j] = total / m
Reported by Philip Ai, 15-Oct-2015.

p. 123

Printed: ...divide by n. The column-by-column...
Fixed: ...divide by m. The column-by-column...
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 124

Printed: The definition extends to matrices that may not be square (see Exercise 1.4.17).
Fixed: The definition extends to matrices that may not be square (see Exercise 1.4.16).
Reported by Huub Everaert, 18-March-2016.

p. 125

Printed: For example, the row-average computation for such a spreadsheet is equivalent to a matrix-vector multiplication where the row vector has n elements all equal to 1.0 / n. Similarly the column-average computation in such a spreadsheet is equivalent to a vector-matrix multiplication where the column vector has m elements all equal to 1.0 / m.
Fixed: For example, the row-average computation for such a spreadsheet is equivalent to a matrix-vector multiplication where the column vector has n elements all equal to 1.0 / n. Similarly the column-average computation in such a spreadsheet is equivalent to a vector-matrix multiplication where the row vector has m elements all equal to 1.0 / m.
Reported by Kevin Xiang Zhong, 2-Jun-2016.

p. 126

Printed: ...whose dimensions are give by the variable m and n.
Fixed: ...whose dimensions are give by the variables m and n.
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 126

Printed: ...provide the basis for a models of the physical world.
Fixed: ...provide the basis for models of the physical world.
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 130

Printed: ...including resizing arrays, linked lists, and binary search trees, and hash tables.
Fixed: ...including resizing arrays, linked lists, binary search trees, and hash tables.
Reported by Diego Sejas Viscarra, 01-Mar-2018.

p. 134, Exercise 1.4.14

Printed: ...have no common factors...
Fixed: ...have no common factors other than 1.
Reported by Diego Sejas Viscarra, 04-Aug-2018.

p. 144, "Anatomy of a formatted print statement" insert

Printed: comversion specification
Fixed: conversion specification
Reported by Diego Sejas Viscarra, 01-Apr-2018.

p. 150, "Description of Program 1.5.2

Printed: ...with fewer than 20 questions
Fixed: ...with at most 20 questions
Reported by Diego Sejas Viscarra, 08-Aug-2018.

p. 152, Program 1.5.3

Printed: The commands shown below after the first one use redirection and piping (discussed in the next subsection) to provide 100,000 numbers to average.py.
Fixed: The commands shown below after the first one use redirection and piping (discussed in the next subsection) to provide 1000 numbers to average.py.
Reported by Diego Sejas Viscarra, 04-Aug-2018.

p. 154

Printed: ...or it might run average.py until it needs some output, and then run randomseq.py until it produces the needed output.
Fixed: ...or it might run average.py until it needs some input, and then run randomseq.py until it produces the needed input.
Reported by Diego Sejas Viscarra, 01-Apr-2018.

p. 167

In the lower right image the white text should be centered in the black square.
Reported by Diego Sejas Viscarra, 28-Nov-2018.

p. 169

Printed: ...most of the ball's pixels alternate between black and white
Fixed: ...most of the ball's pixels alternate between black and gray
Reported by Diego Sejas Viscarra, 04-Aug-2018.

p. 172

Printed: a = stdarray.create1D(n+1)
Fixed: a = stdarray.create1D(n+1, 0.0)
Reported by Diego Sejas Viscarra, 28-Nov-2018.

p. 177, First answer

Printed: You want to use the format 7.2f to specify seven characters in total -- four before the decimal point, the decimal point itself, and two digits after the decimal point.
Fixed: You want to use the format 5.2f to specify five characters in total -- two before the decimal point, the decimal point itself, and two digits after the decimal point.
Reported by Diego Sejas Viscarra, 28-Nov-2018.

p. 179, Exercise 1.5.7

Printed: read from standard input N-1 distinct integers
Fixed: read from standard input n-1 distinct integers
Reported by Bob Dondero, 15-Jun-2015.

p. 179, Exercise 1.5.8

Printed: The harmonic mean is (1/x1 + 1/x2 + ... + 1/xn) / (1/n).
Fixed: The harmonic mean is n / (1/x1 + 1/x2 + ... + 1/xn).
Reported by Swami Iyer, 14-Oct-2015.

p. 180, Exercise 1.5.10

Printed: python randomintseq.py 200 100
Fixed: python randomintseq.py 100 200
Reported by Diego Sejas Viscarra, 13-Nov-2018.

p. 183, Exercise 1.5.24

Printed: of approximate size r times a.length.
Fixed: of approximate size r times len(a).
Reported by Bob Dondero, 15-Jun-2015.

p. 191

The tiny.txt file used in Section 1.6 conflicts with the tiny.txt file used in Section 4.2. Change the name of tiny.txt on this page and throughout Section 1.6 to small.txt.
Reported by Diego Sejas Viscarra, 28-Nov-2018.

p. 192

Printed: for j in range(0, n)
Fixed: for j in range(0, n):
Reported by Diego Sejas Viscarra, 02-Sep-2018.

p. 201

Because of an error in the text file that represents the graph, the numbers on the right side of the page and the histogram at the bottom of the page do not correspond exactly to the graph.
Reported by s.lit.winkler@gmail.com for the Intro to Programming in Java book, 9-Nov-2015.


CHAPTER 2

p. 211

Printed: The diagram on the next page illustrates the flow of conrtol for the command python harmonicf.py 1 2 3
Fixed: The diagram on the next page illustrates the flow of conrtol for the command python harmonicf.py 1 2 4
Reported by Diego Sejas Viscarra, 30-Dec-2018.

p. 214, line 8

Printed: shown at right
Fixed: shown at left
Reported by Huub Everaert, 2-Mar-2016.

p. 211

Printed: def hypot(a, b)
Fixed: def hypot(a, b):
Reported by Diego Sejas Viscarra, 30-Dec-2018.

p. 218, second paragraph

Printed: H2,2 = 49/36
Fixed: H3,2 = 49/36
Reported by Philip Ai, 14-Nov-2015.

p. 220

Printed: def hypot(a, b)
Fixed: def hypot(a, b):
Reported by Diego Sejas Viscarra, 30-Dec-2018.

p. 220

Printed: 0.5*0.982 + 0.5*0.693
Fixed: 0.5*0.982 + 0.5*(-0.693)
Reported by Diego Sejas Viscarra, 30-Dec-2018.

p. 229

Printed: a = stdarray.create1D(n)
Fixed: a = stdarray.create1D(n , 0.0)
Reported by Diego Sejas Viscarra, 30-Dec-2018.

p. 234, inset describing Program 2.1.4

Printed: h[] | combined harmonics
Fixed: harmonics[] | combined harmonics
Reported by Diego Sejas Viscarra, 30-Dec-2018.

p. 235

Printed: ...as illustrated in the figure below...
Fixed: ...as illustrated in the figure to the right...
Reported by Diego Sejas Viscarra, 30-Dec-2018.

p. 235, figure

Printed: stdaudio.playArray(a)
Fixed: stdaudio.playSamples(a)
Reported by Swami Iyer, 03-Oct-2015.

p. 243, Exercise 2.1.22

Printed: (see Exercise 1.4.35)
Fixed: (see Exercise 1.4.36)
Reported by Kevin Xiang Zhong, 3-Jun-2016.

p. 262

Printed: discrete[5, 3, 1, 1]
Fixed: discrete[.5, .3, .1, .1]
Reported by Bob Dondero, 18-Jun-2015.

p. 267, in the table

Printed: x = 0.16y
Fixed: y = 0.16y
Reported by Ivy Gu Zhong, 3-Jun-2016.

p. 274, in the "Plotting a sound wave" inset

Printed: See Program 2.4.7
Fixed: See Program 2.1.4
Reported by Huub Everaert, 18-March-2015.

p. 296, in the "Function call trace for gcd()" insert

Printed: gcd(216, 24)
Fixed: gcd(216, 192)
Reported by Huub Everaert, 20-August-2016.

p. 303, the 12th line of the output of "python beckett 4"

Printed: enter 3
Fixed: exit 3
Reported by Ivy Gu Zhong, 12-June-2016.

p. 314, the second line of the ex235() function

Printed: z = ex233(n-3) + str(n) + ex235(n-2) + str(n)
Fixed: z = ex235(n-3) + str(n) + ex235(n-2) + str(n)
Reported by Kevin Xiang Zhong, 22-June-2016.

p. 315, Exercise 2.3.8

Printed: return mystery(a+a, b/2)
Fixed: return mystery(a+a, b//2)
Reported by Theo Ingelstam, 14-October-2019. Also reported by Rich Downey, 26-November-2019.

p. 315, Exercise 2.3.8

Printed: return mystery(a+a, b/2) + a
Fixed: return mystery(a+a, b//2) + a
Reported by Theo Ingelstam, 14-October-2019. Also reported by Rich Downey, 26-November-2019.

p. 333, in the text describing Program 2.4.5

Printed: ...no different from coin flipping (see Program 2.2.6).
Fixed: ...no different from coin flipping (see Program 2.2.7).
Reported by Huub Everaert, 20-August-2016.

p. 339

Printed: plot the two halves of the curve, from (x0,y0) to (xm,ym), and from (xm, ym) to (x1,y1).
Fixed: plot the two halves of the curve, from (x0,y0) to (xm,f(xm)), and from (xm, f(xm)) to (x1,y1).
Reported by Willem Schaap, 14-Jun-2015.

p. 345, Exercise 2.4.1

Printed: ...with the element in row n and column j set to True if...
Fixed: ...with the element in row i and column j set to True if...
Reported by Kaya, 28-May-2021.

p. 348, Exercise 2.4.21

Printed: ...but with eight recursive calls instead of four.
Fixed: ...but with six recursive calls instead of four.
Reported by Kevin Xiang Zhong, 11-July-2016. Reported by Willem Schaap, 14-Jun-2015.

p. 349, Exercise 2.4.22

Printed: A live cell with exactly one live neighbor becomes dead.
Fixed: A live cell with fewer than two live neighbors becomes dead.
Reported by Julia Yatsenko, 15-Aug-2018.


CHAPTER 3

p. 362

Printed: so this potential is 8.99 × 109 × 0.51 / 0.34 = 1.35 × 1010
Fixed: so this potential is 8.99 × 109 × 21.3 / 0.34 = 5.63 × 1011
Reported by Philip Ai, 14-Nov-2015.

p. 363, in the box showing executions of chargeclient.py

Printed: is 2.56+12
Fixed: is 2.56e+12
Reported by Ivy Gu Zhong, 24-July-2016.

p. 375, first paragraph, sixth line

Printed: ...so the pixel n column 4 and column 6
Fixed: ...so the pixel n column 4 and row 6
Reported by Diego Sejas Viscarra, 6-November-2019.

p. 378

Because of the error in charge.py on page 409, the potential.py image contains three pixels that are white but should be black.
Reported by Kevin Xiang Zhong and Ivy Gu Zhong, 12-Aug-2016.

p. 385, Description of end variable

Printed: </span> after to index
Fixed: </span> after end index
Reported by Diego Sejas Viscarra, 6-November-2019.

p. 388

Printed: (the one at (.51, .63) with potential 21.3)
Fixed: (the one at (.51, .63) with charge value 21.3)
Reported by Ivy Gu Zhong, 16-Aug-2016.

p. 391, in the 4th answer

Printed: For example, 'python'.upper() returns 'Python' and...
Fixed: For example, 'python'.upper() returns 'PYTHON' and...
Reported by Kevin Xiang Zhong, 17-Aug-2016.

p. 393, Exercise 3.1.1

Printed: ...creates four Charge objects that are each distance w...
Fixed: ...creates four Charge objects (each with charge value 1.0) that are each distance w...
Reported by Ivy Gu Zhong, 25-Aug-2016.

p. 404, "Anatomy of a constructor" diagram

Printed:
self._rx = x0
self._rx = x0
Fixed:
self._rx = x0
self._ry = y0
Reported by Ivy Gu Zhong, 06-Sep-2016.

p. 406, first paragraph

Printed: ...the value of the self parameter variable of the __potentialAt__() method is set to c.
Fixed: ...the value of the self parameter variable of the potentialAt() method is set to c.
Reported by Kevin Xiang Zhong, 25-Aug-2016.

p. 409

Printed: and a test client main() (see also Program 3.1.1).
Fixed: and a test client main() (see also Program 3.1.2).
Reported by Ashish, 28-Jun-2015.

p. 409

Printed:
r = math.sqrt(dx*dx + dy*dy)
if r == 0.0: return float('inf')
Fixed:
r = math.sqrt(dx*dx + dy*dy)
if r == 0.0:
    if self._q >= 0.0:
        return float('inf')
    else:
        return float('-inf')
Reported by Kevin Xiang Zhong and Ivy Gu Zhong, 12-Aug-2016.

p. 411

automatic string conversion; Python calls str(c)
automatic string conversion; Python calls c.__str__()
Reported by Yu Cao, 23-July-2018.

p. 413

In stopwatch.py the import math statement is unnecessary.
Reported by Ivy Gu Zhong and Kevin Xiang Zhong, 27-August-2016.

p. 415

Printed: heads = bernoulli.binomial(n, p)
Fixed: heads = stdrandom.binomial(n, p)
Reported by Kevin Xiang Zhong, 29-August-2016.

p. 416, at the beginning of the 3rd paragraph

Printed: For example, to graw a triangle we create a turtle at (0, 0.5) facing...
Fixed: For example, to graw a triangle we create a turtle at (0.5, 0) facing...
Reported by Ivy Gu Zhong, 30-August-2016.

p. 428, Table at bottom

The entry at row z2 and column 2+0i should be 38, not 36.
Reported by Philip Ai, 18-Dec-2015.

p. 438, Second bullet point

Printed: A constant variable name starts with an uppercase letter.
Fixed: A constant variable name consists of uppercase letters.
Reported by Kevin Xiang Zhong, 07-Sep-2016.

p. 439, First question

Printed: You said that mandelbrot.py creates hundreds of millions of complex objects.
Fixed: The mandelbrot.py program creates a huge number of complex objects.
Reported by Kevin Xiang Zhong, 07-Sep-2016.

p. 442, Exercise 3.2.7

Printed: Python provides a data type Fraction, defined in the standard module fraction.py, that implements rational numbers.
Fixed: Python provides a data type Fraction, defined in the standard module fractions.py, that implements rational numbers.
Reported by Ivy Gu Zhong, 08-Sep-2016.

p. 443, Exercise 3.2.8

Printed: a.contains(b): does interval a contain interval b?
Fixed: a.contains(b): does interval a contain b?
Reported by Swami Iyer, 22-Nov-2015.

p. 445, Exercise 3.2.21

Printed: charge.Charge(...)
Fixed: Charge(...)
Reported by Bob Dondero, 25-Jun-2015.

p. 456

Printed: def __abs__(self): return self.r
Fixed: def __abs__(self): return self._r
Reported by Ivy Gu Zhong 13-Nov-2016.

p. 463

Printed: v = new Vector(a)
Fixed: v = Vector(a)
Reported by anonymous, 6-Aug-2015.

p. 471, third line

Printed: ...b would get assigned the integer 33...
Fixed: ...b would get assigned the float 17.46424919657298...
Reported by Kevin Xiang Zhong, 10-Nov-2016.

p. 482

The data in the "Profiling genomic data" table are incorrect. These are the correct data:
        2-gram  hash  count  unit  count  unit
        AA         0      0  0         2  0.139
        AC         1      0  0         1  0.070
        AG         2      3  0.397     2  0.139
        AT         3      4  0.530     1  0.070
        CA         4      2  0.265     2  0.139
        CC         5      0  0         2  0.139
        CG         6      1  0.132     6  0.417
        CT         7      0  0         4  0.278
        GA         8      1  0.132     2  0.139
        GC         9      4  0.530     6  0.417
        GG        10      0  0         2  0.139
        GT        11      0  0         4  0.278
        TA        12      3  0.397     0  0
        TC        13      0  0         5  0.348
        TG        14      1  0.132     4  0.278
        TT        15      0  0         6  0.417
Reported by Huub Everaert, 20-Aug-2016.

p. 483

Printed: for i in range(len(text) - k):
Fixed: for i in range(len(text) - k + 1):
Reported by Kevin Wayne, 23-August-2016.

p. 485

In the "more documents.txt" insert "picture.py" should be "vector.py".
Reported by Bob Dondero 23-Aug-2016.

p. 485

The output of the comparedocuments.py program is incorrect. Specifically, the numbers in the "vect" row and the "vect" column are incorrect. This is the correct output:
    $ python comparedocuments.py 5 10000 < documents.txt
            cons    toms    huck    prej    vect    djia    amaz    actg
    cons    1.00    0.69    0.63    0.67    0.09    0.15    0.19    0.12
    toms    0.69    1.00    0.93    0.89    0.07    0.18    0.19    0.14
    huck    0.63    0.93    1.00    0.83    0.05    0.16    0.16    0.13
    prej    0.67    0.89    0.83    1.00    0.06    0.20    0.20    0.14
    vect    0.09    0.07    0.05    0.06    1.00    0.02    0.19    0.02
    djia    0.15    0.18    0.16    0.20    0.02    1.00    0.11    0.07
    amaz    0.19    0.19    0.16    0.20    0.19    0.11    1.00    0.06
    actg    0.12    0.14    0.13    0.14    0.02    0.07    0.06    1.00
Reported by Kevin Wayne 23-Aug-2016.

p. 490, second question

Printed: Is there is any situation...
Fixed: Is there any situation...
Reported by Ivy Gu Zhong 23-Nov-2016.

p. 499

In the "force from one body to another" illustration the intention is to show a.forceFrom(b). However the arrows marked with a.forceFrom(b), delta.direction(), and delta are in the opposite direction.
Reported by Ivy Gu Zhong 6-Jan-2017.


CHAPTER 4

p. 513, insert

Printed:
python threesum.py < 1Kints.txt
python threesum.py < 2Kints.txt
Fixed:
python threesum.py < 1kints.txt
python threesum.py < 2kints.txt
Reported by Huub Everaert, 8-Sep-2016.

p. 530

Printed: a .insert(0, 'slow')
Fixed: a.insert(0, 'slow')
Reported by Ivy Gu Zhong, 18-Jan-2017.

p. 535

Printed: That is, the code fragment takes quadratic time as a function of the string length n (see Exercise 4.1.13).
Fixed: That is, the code fragment takes quadratic time as a function of the string length n (see Exercise 4.1.15).
Reported by Huub Everaert, 8-Sep-2016.

p. 538, Exercise 4.1.14

Printed: Each of the four Python functions below...
Fixed: Each of the five Python functions below...
Reported by Huub Everaert, 8-Sep-2016.

p. 540, Table

Printed: n-by-n array of floats
Fixed: m-by-n array of floats
Reported by John Spindler, 11-May-2016.

p. 544, Solution to Exercise 4.1.5

Printed: For n > 2, count all the triples that do not include n
Fixed: For n > 2, count all the triples that do not include n-1
Reported by Rich Downey, 21-January-2020.

p. 550, Exercise 4.1.16

Printed: r = stdrandom.uniform(0, n)
Fixed: r = stdrandom.uniformInt(0, n)
Reported by Bob Dondero, 9-Jul-2015.

p. 552, Exercise 4.1.31

Printed:
def no2slash(name):
    for x in range(len(name)):
        if x > 0:
            if (name[x-1] == '/') and (name[x] == '/'):
                for y in range(x+1, len(name)):
                    name[y-1] = name[y]
            else:
                x += 1
Fixed:
def no2slash(name):
    nameList = list(name)
    x = 1
    while x < len(nameList):
        if (nameList[x-1] == '/') and (nameList[x] == '/'):
            for y in range(x+1, len(nameList)):
                nameList[y-1] = nameList[y]
            nameList = nameList[:-1]
        else:
            x += 1
    return ''.join(nameList)
Reported by Huub Everaert, 8-Sep-2016.

p. 553, Exercise 4.1.32

Printed: 99 91 92 93 94
Fixed: 90 91 92 93 94
Reported by Sam, 31-May-2016.

p. 557, "Finding a hidden number with binary search insert

In the insert entitled "Finding a hidden number with binary search" the blue lines in interval 64-80 and interval 72-80 are identical in the graph. The line for 72-80 should be half of the size of the line for 64-80.
Reported by Ivy Gu Zhong, 20-May-2017.

p. 560, "Binary representation" paragraph

Printed: greater than or equal to than 64
Fixed: greater than or equal to 64
Reported by Ivy Gu Zhong, 20-May-2017.

p. 563, Final figure

Printed: equal to 64 + 8 + 4 + 2 + 1
Fixed: equal to 64 + 8 + 4 + 1
Reported by Alex Minos, 7-September-2020.

p. 565, Program 4.2.3

Printed: if a[mid] > key:
Fixed: if key < a[mid]:
Reported by Bob Dondero, 12-Jul-2015.

p. 577, first full paragraph

Printed: The Python system sort uses a version of mergesort:.
Fixed: The Python system sort uses a version of mergesort.
Reported by Huub Everaert, 17-Oct-2016.

p. 587, Exercise 4.2.22

Printed: ...the pair of integers that are closest in value.
Fixed: ...the pair of floats that are closest in value.
Reported by Sam, 16-Jul-2016.

p. 587, Exercise 4.2.23

Printed: ...the pair of integers that are furthest apart in value.
Fixed: ...the pair of floats that are furthest apart in value.
Reported by Sam, 16-Jul-2016.

p. 596

Printed: Node oldFirst = first
Fixed: oldFirst = first
Reported by Anthony Hein, 02-Aug-2019.

p. 598, Description of Program 4.3.2

Printed: We defer the __len__() method to Exercise 4.3.4.
Fixed: We defer the __len__() method to Exercise 4.3.6.
Reported by Yu Cao, 02-October-2020.

p. 633, Exercise 4.3.46

Printed:
-    or 3 3 6 None None None not to  not None None
that    4 3 7 None None None not to  not that None
Fixed:
-    or 3 3 6 None None None not to  be None None
that    4 3 7 None None None not to  be that None
Reported by Sam, 14-Aug-2016.

p. 633, Exercise 4.3.46

Printed:
-    or 3 3 6 None None None not to  not None None
that    4 3 7 None None None not to  not that None
Fixed:
-    or 3 3 6 None None None not to  be None None
that    4 3 7 None None None not to  be that None
Reported by Sam, 14-Aug-2016.

p. 628, Exercise 4.3.33

Printed: (at positions numbered from 0 to n)
Fixed: (at positions numbered from 0 to n-1)
Reported by Alex Minos, 8-September-2020.

p. 664

Printed: import stdio
while not stdio.isEmpty():
Fixed: import stdio
st = dict()
while not stdio.isEmpty():...
Reported by Willem Schaap, 27-Jun-2015.

p. 664

Printed: stdio.writef('%4d %s\n', word, frequency)
Fixed: stdio.writef('%s %4d\n', word, frequency)
Reported by Amir Mahallati, 14-Apr-2015.

p. 671, Exercise 4.4.17

Printed: ... 24 30 30 38 ...
Fixed: ... 24 30 31 38 ...
Reported by Anonymous, 29-Aug-2016.

p. 702, figure

Printed: _prev[w]
Fixed: _edgeTo[w]
Reported by Bob Dondero, 25-Jul-2015.

p. 702, figure

Printed: ORF
Fixed: ORD
Reported by Bob Dondero, 25-Jul-2015.