Question: I am having trouble with this question: IN PYTHON PLEASE Modify the Student class from problem 4 to compute grade point averages. Methods are needed

I am having trouble with this question:

IN PYTHON PLEASE

Modify the Student class from problem 4 to compute grade point averages. Methods are needed to add a grade and get the current GPA. Specify grades as elements of a class Grade. Supply a constructor that constructs a grade from a string, such as B+. You will also need a method that translates grades into their numeric values (for example B+ becomes 3.3). Below is the program that runs the Student and Grade classes.

# Create a new student.

s = Student("Bob")

# Add some quiz grades.

s.addQuiz(Grade("D"))

s.addQuiz(Grade("A-"))

s.addQuiz(Grade("B"))

# Show that the total and the average are computed correctly.

print(s.getName(), "had a total of %.1f grade points." % s.getTotalScore())

print("The GPA was %.1f." % s.getAverageScore())

My code for problem 4 is:

class Student:

#__init__() is a special method which will intialize all the variable of Student Class

def __init__(self, name):

self.name = name

self.totalQuizScore = 0

self.totalQuiz = 0

#This method will return the name of student

def getName(self):

return(self.name)

#This method will add up the score and increase the totalQuiz counter which holds total number of quiz student took

def addQuiz(self,score):

self.totalQuizScore=score+self.totalQuizScore

self.totalQuiz=self.totalQuiz+1

#This method will return total quiz score of particular student

def getTotalScore(self):

return(self.totalQuizScore)

#This method will return average quiz score i.e total score divided by number of quiz

def getAverageScore(self):

return(self.totalQuizScore/self.totalQuiz)

# Create a new student.

s = Student("Bob")

# Add some quiz scores.

s.addQuiz(50)

s.addQuiz(90)

s.addQuiz(75)

# Show that the total and the average are computed correctly.

print(s.getName(), "had a total score of %f." % s.getTotalScore())

print("The average score was %.1f." % s.getAverageScore())

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!