<jupyter_start><jupyter_text>T&T Lab 13 - 26th Feb <NAME>(1828249)  Inheritance1. **Single Inheritance**  When a child class inherits only a single parent class.  2. **Multiple Inheritance**  When a child class inherits from more than one parent class.  3. **Multilevel Inheritance**  When a child class becomes a parent class for another child class  4. **Hierarchical Inheritance**Hierarchical inheritance involves multiple inheritance from the same base or parent class.    Single Inheritance<jupyter_code>class Parent:
     def func1(self):
        print("This function is in parent class.")

class Child(Parent):
     def func2(self):
        print("This function is in child class.")

        
object = Child()
object.func1()
object.func2()<jupyter_output>This function is in parent class.
This function is in child class.<jupyter_text>Multiple Inheritance<jupyter_code>class Mother:
    mothername = ""
    def mother(self):
        print(self.mothername)

class Father:
    fathername = ""
    def father(self):
        print(self.fathername)
        
        
class Son(Mother, Father):
    def parents(self):
        print("Father :", self.fathername)
        print("Mother :", self.mothername)
        
        
s1 = Son()
s1.fathername = "RAM"
s1.mothername = "SITA"
s1.parents()<jupyter_output>Father : RAM
Mother : SITA<jupyter_text>Multi Level Inheritance<jupyter_code>class Grandfather:
    def __init__(self, grandfathername):
        self.grandfathername = grandfathername


class Father(Grandfather):
    def __init__(self, fathername, grandfathername):
        self.fathername = fathername
        Grandfather.__init__(self, grandfathername)

        
class Son(Father):
    def __init__(self,sonname, fathername, grandfathername):
        self.sonname = sonname
        Father.__init__(self, fathername, grandfathername)
 
    def print_name(self):
        print('Grandfather name :', self.grandfathername)
        print("Father name :", self.fathername)
        print("Son name :", self.sonname)

        
        
s1 = Son('Prince', 'Rampal', '<NAME>')
print(s1.grandfathername)
s1.print_name()<jupyter_output><NAME>
Grandfather name : <NAME>
Father name : Rampal
Son name : Prince<jupyter_text>Q1. WAP to represent Hierarchical Inheritance<jupyter_code>class Parent:
      def func1(self):
            print("This function is in parent class.")
            
            
class Child1(Parent):
      def func2(self):
            print("This function is in child 1.")
        
        
class Child2(Parent):
      def func3(self):
            print("This function is in child 2.")
            
            
object1 = Child1()
object2 = Child2()
object1.func1()
object1.func2()
object2.func1()
object2.func3()<jupyter_output>This function is in parent class.
This function is in child 1.
This function is in parent class.
This function is in child 2.<jupyter_text>Q2. Create a class named 'Member' having the following members:  Data members  1 - Name  2 - Age  3 - Phone number  4 - Address  5 - Salary  It also has a method named 'printSalary' which prints the salary of the members.  Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and 'Manager' classes have data members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a manager by making an object of both of these.<jupyter_code>class Member:
    def __init__(self):
        self.name=input("Name: ")
        self.age=int(input("Age: "))
        self.phone=int(input("Phone Number: "))
        self.address=input("Address: ")
        self.salary=int(input("Salary: "))
    def printSalary(self):
        print("Salary: ",self.salary)
        
        
class Employee(Member):
    def __init__(self):
        Member.__init__(self)
        self.specialization=input("Specialization: ")
        

class Manager(Member):
    def __init__(self):
        Member.__init__(self)
        self.department=input("Department: ")
        
        
print("Employee")
emp=Employee()
emp.printSalary()
print("Manager")
mng=Manager()
mng.printSalary()<jupyter_output>Employee
Name: Rayden
Age: 25
Phone Number: 8602432867
Address: Indore
Salary: 50000
Specialization: Android
Salary:  50000
Manager
Name: <NAME>
Age: 20
Phone Number: 9575429455
Address: Delhi
Salary: 100000
Department: Developer
Salary:  100000<jupyter_text>Q3. Create a class with a method that prints "This is parent class" and its subclass with another method that prints "This is child class". Now, create an object for each of the class and call  1 - method of parent class by object of parent class  2 - method of child class by object of child class  3 - method of parent class by object of child class<jupyter_code>class Parent:
     def func1(self):
        print("This function is in parent class.")

class Child(Parent):
     def func2(self):
        print("This function is in child class.")
parent=Parent()
child=Child()
parent.func1()
child.func2()
child.func1()<jupyter_output>This function is in parent class.
This function is in child class.
This function is in parent class.<jupyter_text>Q4. Create a class named 'Shape' with a method to print "This is a shape". Then create two other classes named 'Rectangle', 'Circle' inheriting the Shape class, both having a method to print "This is rectangular shape" and "This is circular shape" respectively. Create a subclass 'Square' of 'Rectangle' having a method to print "Square is a rectangle". Now call the method of 'Shape' and 'Rectangle' class by the object of 'Square' class.<jupyter_code>class Shape:
    def funShape(self):
        print("This is a Shape")

        
class Rectangle(Shape):
    def funRectangle(self):
        print("This is Rectangular Shape")

        
class Circle(Shape):
    def funCircle(self):
        print("This is Circular Shape")

        
class Square(Rectangle):
    def funSquare(self):
        print("Square is a Rectangle")
squareObject=Square()
squareObject.funShape()
squareObject.funRectangle()
squareObject.funSquare()<jupyter_output>This is a Shape
This is Rectangular Shape
Square is a Rectangle<jupyter_text>Q5. Create a class named 'Rectangle' with two data members 'length' and 'breadth' and two methods to print the area and perimeter of the rectangle respectively. Its constructor having parameters for length and breadth is used to initialize length and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle' class with its constructor having a parameter for its side (suppose s) calling the constructor of its parent class as 'super(s,s)'. Print the area and perimeter of a rectangle and a square.<jupyter_code>class Rectangle:
    def __init__(self,l,w):
        self.length=l
        self.width=w
        print("A rectangle created with length {} units and width {} units".format(self.length,self.width))
    def area(self):
        self.a=self.length * self.width
        print("Area is {a:1.2f} square units.".format(a=self.a))
    def perimeter(self):
        self.p=2*(self.length + self.width)
        print("Perimeter is {p:1.2f} units.".format(p=self.p))

class Square(Rectangle):
    def __init__(self,s):
        super().__init__(s,s)

print("Rectangle")
rec=Rectangle(10,20)
rec.area()
rec.perimeter()
print("Square")
sq=Square(10)
sq.area()
sq.perimeter()<jupyter_output>Rectangle
A rectangle created with length 10 units and width 20 units
Area is 200.00 square units.
Perimeter is 60.00 units.
Square
A rectangle created with length 10 units and width 10 units
Area is 100.00 square units.
Perimeter is 40.00 units.<jupyter_text>Q6. Create a class with a method. The method has to decide whether a given year is a leap year or not.**Note**- A year is a leap year if:  •	 It has an extra day i.e. 366 instead of 365.  •	 It occurs in every 4 year e.g. 2008, 2012 are leap years.  •	 For every 100 years a special rule applies-1900 is not a leap year but 2000 is a leapyear. In those cases, we need to check whether it is divisible by 400 or not.<jupyter_code>class LeapYear:
    def check(self,year):
        if (year % 4) == 0:  
            if (year % 100) == 0:  
                if (year % 400) == 0:  
                    print("{} is a leap year".format(year))  
                else:  
                    print("{} is not a leap year".format(year))  
            else:  
                print("{} is a leap year".format(year))  
        else:  
            print("{} is not a leap year".format(year))  
year=LeapYear()
year.check(2000)<jupyter_output>2000 is a leap year
{'fraction_non_alphanumeric': 0.09709078163336839, 'fraction_numerical': 0.02289987148031312, 'mean_word_length': 3.303670186023127, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '657531', 'license': 'Apache-2.0', 'n_tokens_mistral': 2691, 'n_tokens_neox': 2501, 'n_words': 913, 'path': 'T&T Lab 13.ipynb', 'repo_name': 'MrBlu1204/Python', 'size': '8580'}