Single responsibility principle
class Student: def __init__(self, first_name, last_name, grades=[]): self.first_name = first_name self.last_name = last_name self.grades = grades @property def full_name(self): return f'{self.first_name} {self.last_name}' @property def email(self): return f'{self.first_name}{self.last_name[0]}@codewars.com' @property def grade_average(self): return sum(self.grades) / len(self.grades) @property def basic_grades(self): return (('A', 90), ('B', 80), ('C', 70), ('D', 65)) def assess(self): avg = self.grade_average for grade in self.basic_grades: if avg >= grade[1]: return grade[0] return 'F'
- class Student:
- def __init__(self, first_name, last_name, grades=[]):
- self.first_name = first_name
- self.last_name = last_name
- self.grades = grades
- @property
- def full_name(self):
- return f'{self.first_name} {self.last_name}'
- @property
- def email(self):
- return f'{self.first_name}{self.last_name[0]}@codewars.com'
- @property
- def grade_average(self):
- return sum(self.grades) / len(self.grades)
- @property
- def basic_grades(self):
- return (('A', 90), ('B', 80), ('C', 70), ('D', 65))
- def assess(self):
grades = [('A', 90), ('B', 80), ('C', 70), ('D', 65)]- avg = self.grade_average
for grade in grades:- for grade in self.basic_grades:
- if avg >= grade[1]:
- return grade[0]
- return 'F'