0% found this document useful (0 votes)
478 views

Mock Pra 1 Solution Python

The document defines two classes - Chapter and Exam. Chapter contains attributes for a chapter like subject, pages, marks and name. Exam contains an exam name and list of chapters. It defines two methods - findMaximumChapterByPage to return the chapter with maximum pages, and sortChapterByMarks to return a sorted list of marks of chapters. It then takes user input to create Chapter objects, adds them to a list and passes it to an Exam object. It calls the Exam methods to print details of the chapter with maximum pages and sorted list of marks.

Uploaded by

Siva Karthick
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
478 views

Mock Pra 1 Solution Python

The document defines two classes - Chapter and Exam. Chapter contains attributes for a chapter like subject, pages, marks and name. Exam contains an exam name and list of chapters. It defines two methods - findMaximumChapterByPage to return the chapter with maximum pages, and sortChapterByMarks to return a sorted list of marks of chapters. It then takes user input to create Chapter objects, adds them to a list and passes it to an Exam object. It calls the Exam methods to print details of the chapter with maximum pages and sorted list of marks.

Uploaded by

Siva Karthick
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class Chapter:

def __init__(self,subject,pages,marks,name):
self.subject = subject
self.pages = pages
self.marks = marks
self.name = name
class Exam:
def __init__(self,examName,chapterList):
self.examName = examName
self.chapterList = chapterList
def findMaximumChapterByPage(self):
max_obj = max(self.chapterList, key=lambda x:x.pages)
return max_obj
def sortChapterByMarks(self):
ans1 = sorted(self.chapterList, key=lambda x:x.marks)
ans2 = []
for i in ans1:
ans2.append(i.marks)
if len(ans2)==0:
return None
else:
return ans2

count = int(input())
chapterList = []
for i in range(count):
subject = input()
pages = int(input())
marks = int(input())
name = input()
chap = Chapter(subject,pages,marks,name)
chapterList.append(chap)
ex = Exam("ABC",chapterList)
x = ex.findMaximumChapterByPage()
y = ex.sortChapterByMarks()
print(x.subject)
print(x.pages)
print(x.marks)
print(x.name)
for i in range(len(y)):
print(y[i])

You might also like