Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use PYTHON only and follow all the following instructions carefully. Than

ID: 3598334 • Letter: P

Question

Please use PYTHON only and follow all the following instructions carefully. Thank you

Please make sure that it can pass all the test cases as follows: https://repl.it/Mz4Z/2

Task 1 - Grade A Grade represents a specific score on a specific kind of assessment (and has its own assumedly unique name). This is just a "container" type, used to give memorable names to individual grouped sub-values. class Grade: Define the Grade class. def init__(self, kind, name, percent): Grade constructor. All three parameters must be stored to instance variables of the same names (kind, name, and percent). If kind is not one of "test", "lab", "project", or "final" (example: kind." survey"), then raise a GradingError with the message "no Grade kind ' survey". (You can skip this exception-raising part until later) o kind : str. Should be something like "lab", "test", or "project". o name :: str. Could be something like "L1", "T2", or "P6" o percent :int. (I chose int to simplify the assignment, but float would have been useful) def-str-(self): returns a human-centric string representation. Ifkinde="test",name="T1", and percents-97, then the returned string must be "test : T1(97%)" (no padded zeroes). def_repr__(self): returns a computer-centric string representation. As is often the case, we want to construct a string that could be pasted back into the interactive mode to re-create this object. Given the same example as in_str_we need to return the string "Grade('test 'T1', 97)". Note: we choose to always use single-quotes. def _eq_(self, other): we want to check that two grades are equal (our self and this other grade). We compare each instance variable like so (this is the definition!) return self . kinde#0ther . kind and self .name==other . name and self .percente:other . percent

Explanation / Answer

class Grade:
def __init__(self, kind, name, percent):
if (not kind in ["test", "lab", "project", "final"]):
raise GradingError("no Grade kind '" + str(kind) + "'")
  
self.kind = kind
self.name = name
self.percent = percent
def __str__(self):
return self.kind + ":" + self.name + "(" + str(self.percent) + "%)"
def __repr__(self):
return "Grade('" + self.kind + "', '" + self.name + "', " + str(self.percent) + ")"
def __eq__(self, other):
return self.name == other.name and self.kind == other.kind and self.percent == other.percent

class GradeBook:
def __init__(self):
self.grades = []
def __str__(self):
gradebookstr = "GradeBook: "
for grade in self.grades:
gradebookstr += " " + str(grade) + " "
return gradebookstr
def __repr__(self):
return str(self)
  
def add_grade(self, grade):
self.grades.append(grade)
  
def average_by_kind(self, kind):
count = 0
kindSum = 0
for grade in self.grades:
if grade.kind == kind:
kindSum += grade.percent
count += 1
if count == 0:
return None
return float(kindSum)/count
  
def get_all_of(self, kind):
kind_list = []
for grade in self.grades:
if grade.kind == kind:
kind_list.append(grade)
return kind_list
def get_by_name(self, name):
for grade in self.grades:
if grade.name == name:
return grade
raise GradingError("no Grade found named '" + str(name) + "'")
  

class GradingError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return self.msg
def __repr__(self):
return "GradingError('''" + self.msg + "''')"

# copy pastable code: https://paste.ee/p/PZTVu

'''

Sample run

Running required definitions:
.........................
----------------------------------------------------------------------
Ran 25 tests in 0.001s

OK

25/25 Required test cases passed (worth 4 each)

'''