Friday, February 20, 2009

Chapter 2 -- Page 52 -- Listing 2.2

This code, as it evolved in Section 2.4.1, is not wrong but it does have an unfortunate use of identifier names.  The name sideS is meant to refer to the length of side S in the triangle shown. However, the parameter, sides, refers to the number of sides in the polygon being used for the approximation.  Since Python is case sensitive, these are two different names.  But they can easily be confused as seen in Line 12.  It would certainly have been better to name the parameter something like numSides.

Thursday, February 12, 2009

Chapter 1 Programming Exercise 1.3

This exercise asks the student to generalize the previous exercise from a five pointed star to an n pointed star. The instructions should include the limitation that n will be odd.

Wednesday, February 11, 2009

Chapter 1 Session 1.5 caption

The caption for session 1.5 should read Calculating the volume of a cylinder with assignment statements. The caption in the book incorrectly says sphere.

Chapter 1: Sum of first n integers

The formula on page 8 is a little confusing for our mathematician friends. To be perfectly correct the formula should read:

0349BB8B-EDCB-49E5-8FF3-13CE7E447732.jpg

Tuesday, February 10, 2009

Chapter 9 -- Page 314 -- Listing 9.4

The recursive calls to sierpinski in lines 14,15, and 16 have an extra comma at the end of the parameter list as shown below.
sierpinski(myTurtle,p1,midPoint(p1,p2),midPoint(p1,p3),depth-1,)
sierpinski(myTurtle,p2,midPoint(p2,p3),midPoint(p2,p1),depth-1,)
sierpinski(myTurtle,p3,midPoint(p3,p1),midPoint(p3,p2),depth-1,)
This is a typo.  Although these extra commas do not cause any syntactic problem, they should be removed.

Friday, February 6, 2009

Chapter 7 -- Page 258 -- Listing 7.12

Line 15 refers to a variable k that is undefined in this function.  k has been used to denote the number of clusters.  Lines 3 and 4 tell us that we are creating 6 clusters of earthquakes.  k should be 6 in line 15.

Wednesday, February 4, 2009

Chapter 4 -- Page 128 -- Problem 4.6d

This problem asks you to implement a function that works like the list method find. Of course, there is no method find...it should be index. The problem should read...  Implement a function that works like the list method index.

Chapter 6 -- Page 222 -- Exercise 6.23 typo

There is a typo in exercise 6.23.  It should read  "Write a general function for enlarging..."

Chapter 6 -- Page 220 -- Listing 6.9

This listing has transposed the width and height in lines 7 and 8.  The row should iterate over the height and the column over the width.  The correct version is:
   
def double(oldimage):
oldw = oldimage.getWidth()
oldh = oldimage.getHeight()

newim = EmptyImage(oldw*2,oldh*2)

for row in range(newim.getHeight()):
for col in range(newim.getWidth()):

originalCol = col//2
originalRow = row//2
oldpixel = oldimage.getPixel(originalCol,originalRow)

newim.setPixel(col,row,oldpixel)

return newim