# ------------------------------------- # File: Xiang/002.py # Author: Mihaela Malita # Title: OO Shapes: Polymorphism: area of circle and square # Run: # area of shape is 1 # area of shape is 25 # area of shape is 3.14159265359 # area of shape is 78.5398163397 # ------------------------------------- from math import pi class mySquare: def __init__(self,s): self.side = s def area(self): return self.side ** 2 class myCircle: def __init__(self,r): self.radius = r def area(self): return pi * self.radius ** 2 def main(): # make a list of shapes mylist= [mySquare(1),mySquare(5),myCircle(1),myCircle(5)] # print the coresponding areas for i in mylist: print "area of shape is ", i.area() main()