Question
class Student(object): def __init__(self, fname, lname, major): self.fname = fname self.lname = lname self.gradePoints = {} #empty dictionary self.major = major def addGrade(self, category, grade):
class Student(object): def __init__(self, fname, lname, major): self.fname = fname self.lname = lname self.gradePoints = {} #empty dictionary self.major = major def addGrade(self, category, grade): #your code here #fill out the gradePoints per category #category is key and grade is value def getPercentage(self): #your code here #calculate grade percentage from gradePoints dictionary #sum over all values and divide by the length of dictionary #return the percentage def __str__(self): #your code here #return full name and major
#object creation s1 = Student('John', 'Doe', 'IT') s2 = Student('Peter', 'Pan', 'CS')
s1.addGrade('Lab', 90) s1.addGrade('Quiz', 100) s1.addGrade('Homework', 80) print(s1) print('Grade percentage: ', s1.getPercentage())
s2.addGrade('Lab', 80) s2.addGrade('Quiz', 70) s2.addGrade('Homework', 75) print(s2) print('Grade percentage: ', s2.getPercentage())
Sample Output
Name: John Doe,
Major: IT
Grade Percentage: 90.0
Name: Peter Pan,
Major: CS
Grade Percentage: 75.0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started