Python multilevel inheritance

In this python program, multilevel inheritance is implemented  by creating person as base class, employee class is inherited from person class and next level of inheritance is done by creating manager class which inherit employee class so there are two parent classes in hierarchy. multilevel.py class person: def getName(self,fname,lname): self.fname = fname self.lname = lnameContinue reading “Python multilevel inheritance”

Python multiple inheritance

In this program, customer class is inherited from address and contact class. So customer class can use functions defined in address and contact class. multiple.py class address:  def getAddress(self, city,state):   self.city=city   self.state=state  def showAddress(self):   print(“City: “,self.city)   print(“State: “,self.state) class contact:  def getContact(self,email,cell):   self.email=email   self.cell=cell  def showContact(self):   print(“Email: “,self.email)Continue reading “Python multiple inheritance”

Python user defined exception

In this example, user defined exception is used for handling negative value for salary input and built in exception value error is used for handling non-numeric value. exceptiondemo.py class NegativeSalary(Exception):  pass class LimitExceeding(Exception):  pass def salaryInput():  try:   Salary=int(input(“Enter Your Salary :”))   if Salary<0:    raise NegativeSalary   elif Salary>50000:    raise LimitExceeding  Continue reading “Python user defined exception”