Again, these initializations can simply be 1 and 2 since the division performed will automatically return floating point.
The correction should be made to lines 2 and 3 of Listing 2.4 as well.
Wednesday, August 26, 2009
Chapter 2 -- Page 54 -- Problem 2.6
In this problem we are testing the archimedes function to see how many sides are required to get the same result as that provided by the math library (math.pi).
Instead of "How many repetitions..." the question should ask "How many sides..."
Also, the values may never be equal. When are they "close enough" to call them equal?
Instead of "How many repetitions..." the question should ask "How many sides..."
Also, the values may never be equal. When are they "close enough" to call them equal?
Chapter 2 -- Page 47 -- Second line and Session 2.1
This line of text refers to floating point division and states that it is necessary for one of the operands to be a floating point number. This is NOT necessary. Division ("single slash") in Python 3 is always assumed to be floating point. So 22/7 will yield the correct result.
22.0, 355.0, and 9801.0 can simply be 22, 355, and 9801 in Session 2.1
22.0, 355.0, and 9801.0 can simply be 22, 355, and 9801 in Session 2.1
Chapter 1 -- Page 13 -- Problem 1.6
This problem needs better wording, something like
Compute the number of handshakes required for each person in your class to shake hands with every other person exactly one time.
Compute the number of handshakes required for each person in your class to shake hands with every other person exactly one time.
Monday, August 24, 2009
Chapter 12 -- Listing 12.8
There is a typo in Listing 12.8. In the init method the instance variable is visibleObjects. The b is missing in the text. In addition, the calls to up() and tracer should be added to the drawAll() method as they are in listing 12.4
Here is a complete, corrected version of Listing 12.8
Here is a complete, corrected version of Listing 12.8
class Canvas:
def __init__(self,w,h):
self.width = w
self.height = h
self.visibleObjects = []
self.turtle = cTurtle.Turtle()
self.turtle.setup(width=self.width,height=self.height)
self.turtle.hideturtle()
def drawAll(self):
self.turtle.reset()
self.turtle.tracer(0)
for shape in self.visibleObjects:
shape._draw(self.turtle)
self.turtle.tracer(1)
self.turtle.hideturtle()
def addShape(self,shape):
self.visibleObjects.append(shape)
def draw(self,gObject):
gObject.setCanvas(self)
gObject.setVisible(True)
self.turtle.up()
self.turtle.tracer(0)
gObject._draw(self.turtle)
self.turtle.tracer(1)
self.addShape(gObject)
Wednesday, May 20, 2009
Chapter 8 -- Exercise 8.11
Question 8.11 asks you to provide the sort function a cmp function rather than a keyword function. This is old school. In Python 3.0 cmp was removed.
Friday, May 8, 2009
Listing 12.1
Lines 4, 6, and 16 incorrectly call a method named fillColor. the name of the method should be setFill. For example line 4 should read house.setFill('blue')
Subscribe to:
Posts (Atom)