-Program defines a class CIRCLE that stores radius of circle as instance member. It also maintain a list containing radii of all circles created so far. Class maintains the value of π.
-Class has methods for constructor, area, total circles to return no. of circle objects created.
-There should be doc string for each class.
-Output should be able to show total circles created so far as well as the details of latest circle created.
-Write a main function to implement the other methods of the class.
In [1]:
class CIRCLE(object):
'''Class to implement a CIRCLE type object with the following attributes:
-radius
And the following methods:
-area(): Returns area of instance
-totalCircles(): Returns number of circles created'''
all = []
pi = 3.14159265358979323846264
def __init__(self,radius):
self.radius = radius
CIRCLE.all.append(radius)
def area(self):
return CIRCLE.pi * (self.radius)**2
def totalCircles(self):
return len(CIRCLE.all)
In [14]:
def main():
clist = [CIRCLE(5) for i in xrange(10)] #Create 10 circles with radius 5
print clist[1].totalCircles()
print clist[0].area()
In [ ]: