1.

Write a Python program to demonstrate multiple inheritance. Consider 3 classes with the following description.Student class has 3 protected data members roll number, mark1 and mark2 of type integer. It has a get() function to get these details from the user. Sports class has a protected data member sports marks of type integer and a function getsm() to get the sports mark.Statement class uses the marks from Student class and the sports marks from the Sports class to calculate the total and average and displays the final result

Answer»

class student(object):

# constructor to create an object def init (self):

self.mo=0

self.m1=0

self.m2=0

def get(self):

self.mo=int(raw_input(“Enter the Roll no:”))

print “Enter 2 marks”

self.m1=int(raw_input(“Markl?”))

self.m2=int(raw_input(“Mark2 ?”))

classsports(object):

# Sports mark

def_init_(self):

self.sm=0

def getsm(self):

self.sm=int(raw_input(“Enter the sports mark:”))

class statement(student,sports):

def_init_(self):

super(statement,self)._init_()

def display (self):

tot=(self.ml+self.m2+self.sm); avg=tot/3;

print“\n\n\tRoll No. : ”,

self.mo,“\n\tTotal :”,tot print“\tAverage : ”,avg

obj=statement()

obj.get()

obj.getsm()

obj. display()



Discussion

No Comment Found