from random import choice class Student: def __init__(self, first_name, last_name): self.first_name = first_name self.last_name = last_name self.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' def add_grade(self, grade): self.grades.append(grade) @property def grade_average(self): if not self.grades: return 0 return sum(self.grades) / len(self.grades) def assess(self): if not self.grades: return 'Ungraded' avg = self.grade_average if 0 <= avg <= 25: return 'B-' elif 25 < avg <= 50: return 'B+' elif 50 < avg <= 75: return 'A-' elif 75 < avg <= 100: return 'A+' def add_random_grade(self): random_grade = choice(range(1, 11)) self.grades.append(random_grade)
- from random import choice
- class Student:
- def __init__(self, first_name, last_name):
- self.first_name = first_name
- self.last_name = last_name
- self.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'
- def add_grade(self, grade):
- self.grades.append(grade)
- @property
- def grade_average(self):
- if not self.grades:
return None- return 0
- return sum(self.grades) / len(self.grades)
- def assess(self):
- if not self.grades:
return None- return 'Ungraded'
- avg = self.grade_average
if avg >= 90:return 'A'elif avg >= 80:return 'B'elif avg >= 70:return 'C'elif avg >= 65:return 'D'else:return 'F'- if 0 <= avg <= 25:
- return 'B-'
- elif 25 < avg <= 50:
- return 'B+'
- elif 50 < avg <= 75:
- return 'A-'
- elif 75 < avg <= 100:
- return 'A+'
- def add_random_grade(self):
- random_grade = choice(range(1, 11))
- self.grades.append(random_grade)