1.

Write a Python program using classes and objects to simulate result preparation system for 20 students. The data available for each student includes: Name, Roll no, and Marks in 3 subjects. The percentage marks and grade are to be calculated from the following information:Percentage Of MarksGrade80 to 100A60 to 80B45 to 60CLess than 45DGRADE FORMULAAlso demonstrate constructor overloading.

Answer»

# constructor to create an object

def init (self,s=None):

#non-copy constructor if s==None:

self.rollno = 0 self.name = ‘ ’

self.marks = [0,0,0]

self.avg = 0.0 self.grade = ‘ ’

# copy constructor else:

self.rollno = s.rollno self.name = s.name self.marks = s.marks self.avg = s.avg

self.grade = s.grade

def read (self):

# This function gets the details of a student from the user

selfrollno=iaw_input(“Enter roll number.-’)

self.name = raw_input(“Enter name:-”) s=0

for i in range(0,3):

self.marks [i] = int(r a w_input (“Enter the marks ?”)) s = s + self.marksfi] self.avg = s/3

if(self.avg>60):

self.grade=‘A’

elif self.avg>40:

self.grade=‘B’

else:

self.grade=‘C’

def display (self):

# This function prints each student’s details

print self.rollno,“\t”, self, name, “\t\ t”,

self.grade s = StudentO studlist = []

num = int(raw_input(“Enter no. of students:-’’))

for i in range(O.num):

s.read()

studlist. append(Student(s))

print “ STUDENT REPORT \n”

print “***********************************\n”

print “RollNo \t Name \t\t Grade”

print “*******************************************\n”

for i in range(0,num):

studlist[i] .displayO

#Initialize avg as the first student’s avg maxavg = studlist[0].avg totavg = 0

for i in range(l.num):

totavg = totavg + studlist[i].avg if studlist[i].avg > maxavg: maxavg = studlist[i].avg

topper = studlist[i].name totavg = totavg/num

print “Class topper is”,studlist[i],name,“with average”, studlist [i]. avg

print “Class average is”,totavg

class Student:



Discussion

No Comment Found