-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCh10_DesignWithClasses
36 lines (29 loc) · 1.2 KB
/
Ch10_DesignWithClasses
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
File: student.py
Resources to manage a student's name and test scores
"""
class Student(object):
"""Represents a student. Object is parent class name. This is the Class Header"""
def __init__(self, name, number):
"""Constructor creates a Student with the given name and number of scores and sets all scores to 0. This is a method header"""
self.name = name
self.scores = []
for count in range(number):
self.scores.append(0)
def getName(self)
"""Returns the students name"""
return self.name
def setScore(self, i, score):
"""Resets the ith score, counting from 1."""
def getScore(self, i):
"""Returns the ith score, counting from 1"""
return self.scores[i-1]
def getAverageScore(Self):
"""Returns the Average score"""
return sum(self.scores)/ len(self.scores)
def getHighScore(self):
"""Returns the Highest Score"""
return max(self.scores)
def __str__(self):
"""Returns the string representation of the student"""
return "Name: " + self.name + "\nScores: " + \ " " .join(map(str, self.scores))