[Tutor] ask-why I cannot run it, and I am so confused about the traceback

Shurui Liu (Aaron Liu) shurui91 at gmail.com
Wed Apr 7 12:56:27 CEST 2010

# Filename: classVolume.py
# Demonstrates multiple classes per program.

class Cube:
   """A class for cube shapes."""
   def __init__(self, side):
       self.side = side
   def calculateArea(self):
       return (self.side)**3.0

class Sphere:
   """A class for sphere shapes."""
   def __init__(self, radius1):
       self.radius1 = radius1
   def calculateArea(self):
       import math
       return (4/3)*(math.pi)*((self.radius1)**3.0)

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)

Shurui Liu (Aaron Liu)
Computer Science & Engineering Technology
University of Toledo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100407/50203d67/attachment.html>

More information about the Tutor mailing list