Click to view the other books

If you find any typos, please email them to [email protected]. (Apologies in advance if I haven't posted your errata submission yet or failed to give credit. Please email me to correct this.)

Chapter 4 - Guess the Number

The "Converting Strings to Integers with the int() Function" section has an example of the int() function which reads:

Traceback (most recent call last):
File "", line 1, in 
int('forty-two')
ValueError: invalid literal for int() with base
...when it should read int('hello') (Thanks to David Dantowitz)

Chapter 10 - Tic Tac Toe

The "The First if Statement (Cats and Dogs)" section has the line "on line 9 in our small program will first evaluate TrueFizz()", when it should be "on line 9 in our small program will first evaluate FalseFizz()". (Thanks to Ben White)

Short-Circuit Evaluation section has the line "The only times move not in '1 2 3 4 5 6 7 8 9'.split() evaluates to False are when move is not a single-digit string.". The second "not" should be removed to read: "The only times move not in '1 2 3 4 5 6 7 8 9'.split() evaluates to False are when move is a single-digit string." (Thanks to Sebastian Simon.)

Chapter 11 - Bagels

The "The sort() List Method" section has this example:

>>> spam = [5, 'bat', 3, 1, 4, 'cat', 2, 'ape']
>>> spam.sort()
>>> spam
[1, 2, 3, 4, 5, 'ape', 'bat', 'cat']
While this code works in Python 2, it won't work in Python 3 because it gives this error:
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unorderable types: str() < int()
The reason is because in Python 3 the integer and string values are not automatically comparable to each other. You would need to run this line of code: spam.sort(key=str) which would pass all the values (such as the 5, 3, 1, 4, and 2 integer values) to the str() function first and then use the return value for sorting comparison.

This code was left over from the first edition of the book that used Python 2. (Thanks to "Team Liquid")

Chapter 13 - Sonar

Line 148 of the source code says The point where the device was dropped will be marked with a d. when it should say The point where the device was dropped will be marked with a 2. (Thanks to Sia Kia)

Chapter 17 - Graphics and Animation

On page 336, there is the text "If you forget to delete the Surface object" which should be "If you forget to delete the PixelArray object". (Thanks to Jerry Zhao)