[Tutor] ask-why I cannot run it, and I am so confused about the traceback
Martin A. Brown
martin at linux-ip.net
Wed Apr 7 13:02:31 CEST 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Greetings,
: class Cone:
: """A class for cone shapes."""
: def __init__(self, radius2, height):
: self.radius2 = radius2
: self.height = height
: def calculateArea(self):
: import math
: return (1/3.0)*(math.pi)*(self.height)*((self.radius2)**2)
:
:
: # Create a list of volumes.
: list = [Cube(1.1),Cube(1.2),Sphere(1.1),Sphere(1.2),Cone(1.1),Cone(1.2)]
:
: # Print out the list contents.
: for volume in list:
: print "The volume is: ", volume.calculateArea()
: raw_input("\n\nPress the enter key to exit.")
: Traceback (most recent call last):
: File "classVolume.py", line 30, in <module>
: list = [Cube(1.1),Cube(1.2),Sphere(1.1),Sphere(1.2),Cone(1.1),Cone(1.2)]
: TypeError: __init__() takes exactly 3 arguments (2 given)
Look at your __init__ method for Cone().
Look at your invocation.
Each call to Cone only supplies a single argument.
... Cone(1.1),Cone(1.2) ...
- -Martin
- --
Martin A. Brown
http://linux-ip.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: pgf-0.72 (http://linux-ip.net/sw/pine-gpg-filter/)
iD8DBQFLvGZJHEoZD1iZ+YcRAikGAJ4gkDCl6ljej92QFx0VfYgh3jPUFACfUlWD
Yx6ZZiTTs6JIxulV+RcWucU=
=fhP5
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list