The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

This topic is READ ONLY
kamaboko (5) [Avatar] Offline
#1
Hi,

I'm doing this sample problem, and keep getting the following message:

myBall = Ball("red", "small", "down")
TypeError: this constructor takes no arguments

Here's my code. It looks right to me.

class Ball:

def _init_(self, color, size, direction):
self.color = color
self.size = size
self.direction = direction

def bounce(self):
if self.direction == "down":
self.direction = "up"

myBall = Ball("red", "small", "down")
print "I just created a ball."
print "My ball is", myBall.size
print "My ball is", myBall.color
print "My ball's direction is", myBall.direction
print
myBall.bounce()
print "Now my ball's direction is", myBall.direction
carter.sande (32) [Avatar] Offline
#2
Re: Chapter 14, list 14.3.....constructor not taking argument?
Hey there!

It looks like you just made a simple typo.

_init_ (one underscore on each side)
should be:
__init__ (two underscores)

Let me know if that helps!

Carter
kamaboko (5) [Avatar] Offline
#3
Re: Chapter 14, list 14.3.....constructor not taking argument?
Indeed you are correct. This is probably why I don't work at Google...yet.

Thanks,
K
Bennjamin (27) [Avatar] Offline
#4
Re: Chapter 14, list 14.3.....constructor not taking argument?
actually, i kept making that mistake until i finally found the problem in Errata, where it stated that they should mention that __init__ has 2 underscores, not one.