Multiple Inheritance

#!/usr/bin/evn python

# Define a class as 'person'
class person:
    # Constructor
    def __init__(self):
        self.name = input("Name: ")
        self.age = input("Age: ")
        self.gender = input("Gender: ")
    
    # Method
    def display(self):
        print("\n\nName: ",self.name)
        print("Age: ",self.age)
        print("Gender: ",self.gender)
        

# Define a class as 'marks'
class marks:
    # Constructor
    def __init__(self):
        self.stuClass = input("Class: ")
        print("Enter the marks of the respective subjects")
        self.literature = int(input("Literature: "))
        self.math = int(input("Math: "))
        self.biology = int(input("Biology: "))
        self.physics = int(input("Physics: "))
     
     # Method
    def display(self):
        print("Study in: ",self.stuClass)
        print("Total Marks: ", self.literature + self.math + self.biology + self.physics)
        

# Define a class as 'student' and inherit two super classes 'person' and 'marks'
class student(person, marks):
    def __init__(self):
        # Call constructor of super class 'person'
        person.__init__(self)
        # Call constructor of super class 'marks'
        marks.__init__(self)
        
    def result(self):
        # Call method of class 'person'
        person.display(self)
        # Call method of class 'marks'
        marks.display(self)
        
# Objects of class 'student'
stu1 = student()
stu2 = student()

# Call method of class 'student'
stu1.result()
stu2.result()



#***** Output *****

Name: James
Age: 16
Gender: Male
Class: 10th
Enter the marks of the respective subjects
Literature: 30
Math: 50
Biology: 40
Physics: 8
Name: Sonam
Age: 15
Gender: Female
Class: 9th
Enter the marks of the respective subjects
Literature: 20
Math: 60
Biology: 70
Physics: 60


Name:  James
Age:  16
Gender:  Male
Study in:  10th
Total Marks:  128


Name:  Sonam
Age:  15
Gender:  Female
Study in:  9th
Total Marks:  21

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!