class Student():
def __init__(self,n,m):
self.sname = n
self.major = m
self.courses = []
self.gpa = 0
def add_course(self,cnum,credits,grade):
self.courses.append((cnum,credits,grade))
def gpa(self):
points_for_grade = {'A':4,'B':3,'C':2,'D':1,'F':0}
grade_points = 0
num_credits = 0
for course in self.courses:
num_credits += course[1]
grade_points += course[1]*points_for_grade[course[2]]
if num_credits != 0:
return grade_points/num_credits
else:
return None
def __str__(self):
return "(" + self.sname + "," + self.major + "," + str(self.courses) + ")"