human
I am working on the file "Section 1 - Core Python/Chapter 09 - Classes & OOPS/01_Classes_and_OOPS.ipynb".
The first task is:
Regulating number of object creation
we are going to tweak previous example and convert it to have a finite number of objects created for the class
Can you write Python program for it?
 ... Can you provide a the Python program you requested?
assistant
#Here is the Python program you requested.

class HeadMaster(object):
    _instances = []  # Keep track of instance reference
    limit = 2

    def __new__(cls, *args, **kwargs):
        if len(cls._instances) >= cls.limit:
            raise RuntimeError("Creation Limit %s reached" % cls.limit)
        instance = object.__init__(cls)
        cls._instances.append(instance)
        return instance

    def __del__(self):
        self._instance.remove(self)

try:
    li1 = HeadMaster()
    li2 = HeadMaster()
    li3 = HeadMaster()
    li4 = HeadMaster()
except Exception as e:
    print(e)