Question: Jack is testing the Student class developed earlier in this chapter. He creates an instance of this class with 0 scores and receives an error
Jack is testing the Student class developed earlier in this chapter. He creates an instance of this class with scores and receives an error message when he attempts to view the average score:
s StudentJack
prints
Name: Jack
Scores:
sgetAverageScoreScore
Traceback most recent call last:
File line in
sgetAverageScore
File Userskenpythonfilesstudentpy line in getAverageScoreScore
return sumselfscores lenselfscores
ZeroDivisionError: division by zero
Explain the error detected during this test and prevent it from happening.
File: student.py
Resources to manage a student's name and test scores.
class Studentobject:
Represents a student."""
def initself name, number:
All scores are initially
self.name name
self.scores
for count in rangenumber:
self.scores.append
def getNameself:
Returns the student's name."""
return self.name
def setScoreself i score:
Resets the ith score, counting from
self.scoresi score
def getScoreself i:
Returns the ith score, counting from
return self.scoresi
def getAverageScoreself:
Returns the average score."""
return sumselfscores lenselfscores
def getHighScoreself:
Returns the highest score."""
return maxselfscores
def strself:
Returns the string representation of the student."""
return "Name: self.name
Scores:
joinmapstr self.scores
def main:
s StudentJack
prints
sgetAverageScore
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
