# 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
419-508-1228
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to