I have to create the following class, but I am unsure of how to set up my constructor.
A GradeRecords object has the following attributes:
term: a string representing the current semester;grades: a list object containing tuples, where the first entry of each tuple is a string representing the code of the class, the second entry of each tuple is the grade out of 100, and the third entry is the number of credits for this course.gradescan be initialized as an empty list.num_courses: an int which contains the number of courses in the record.
This can be initialized as 0.
You are not allowed to add more attributes.
Furthermore, a GradeRecords object has the following methods:
- an initialization method which takes as input the current term and initializes the three attributes;
- add_course, a method which takes a string representing the course code, an int for the grade out of 100 and the number of credits. The method adds a new tuple to grades.
My code give me the error:
g1 = GradeRecords("Fall 2021")
TypeError: __init__() missing 1 required positional argument: 'new_tuple'
Thank you!
class GradeRecords:
grades = []
num_courses = 0
def __init__(self, term, new_tuple):
self.term = term
#create a list from the input new_tuple
self.grades.append(new_tuple)
GradeRecords.num_courses += len(self.grades)
def add_course(self, course_code, grade_100, num_credits):
new_tuple = (course_code, grade_100, num_credits)
self.grades.append(new_tuple)
return grades
__init__method doesn't need a "new_tuple" parameter and it shouldn't append anything to "self.grades" as the assignment doesn't request that.