-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.py
More file actions
29 lines (27 loc) · 994 Bytes
/
student.py
File metadata and controls
29 lines (27 loc) · 994 Bytes
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
class Student:
"""
A class representing a student who has a Boolean/int List representing
how many questions were graded right (1) or wrong (0) and a full name.
"""
def __init__(self, fname):
"""
A constructor that takes in a String representing the student's name
and initializes this Student's grades to be a new empty list.
"""
self.fullname = fname
self.grades = []
def __str__(self):
"""
A method to overwrite the built in object method __str__
to display the student's name and grade.
"""
return f'Final grade of {self.fullname} is {(self.get_average() * 100):.2f}%'
def get_average(self):
"""
A helper method to get the fraction of correct answers
this student currently has reflected by their grades list.
"""
total = 0
for grade in self.grades:
total += grade
return total / len(self.grades)