Question: # student.py # VM # inspired by shop.py # ------- # Licensing Information: You are free to use or extend these projects for # educational
# student.py # VM
# inspired by shop.py # ------- # Licensing Information: You are free to use or extend these projects for # educational purposes provided that (1) you do not distribute or publish # solutions, (2) you retain this notice, and (3) you provide clear # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. # # Attribution Information: The Pacman AI projects were developed at UC Berkeley. # The core projects and autograders were primarily created by John DeNero # (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). # Student side autograding was added by Brad Miller, Nick Hay, and # Pieter Abbeel (pabbeel@cs.berkeley.edu).
class Student:
def __init__(self, name, courseUnits): """ name: Name of the student
courseUnits: Dictionary with keys as course strings and units for values e.g. {'math':4.0, 'science': 3.0, 'art':2.0} """ "*** YOUR CODE HERE ***" # self.courseUnits = self.name = name print('Student %s registered' % (name))
def getCourseUnits(self, course): """ course: Course string Returns units of 'course', assuming 'course' is in courseUnits dictionary or None otherwise """ if course not in self.courseUnits: print("Student not registered for", course) "*** YOUR CODE HERE ***"
def getGPA(self, gradeList): """ gradeList: List of (course, grade) tuples
Returns GPA given gradeList, only including the grades of courses that this student has registered for """ "*** YOUR CODE HERE ***"
def getName(self): return self.name
def __str__(self): return "
def __repr__(self): return str(self)
1. The initialization method, takes the name of the student, as well as courseUnits, a dictionary with keys as course strings and units for values e.g. {'math':4.0, 'science': 3.0, 'art':2.0} and sets the related class variables.
2. Method getCourseUnits(self, course) which looks up course and returns units of 'course', assuming 'course' is in courseUnits dictionary or None otherwise
3. Method getGPA(self, gradeList), which given gradeList, a list of (course, grade) tuples, calculates and returns GPA, only including the grades of courses that this student has registered for (those available in courseUnits). If none of the courses are in courseUnits, it will return None.
Please answer the above 3 questions in PYTHON CODE in steps, thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
