Ad

I suck at tests

Code
Diff
  • 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 sum(self.grades) / len(self.grades)
        
        def assess(self):
            if not self.grades:
                return None
            
            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'
                
        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, grades=[]):
    • def __init__(self, first_name, last_name):
    • self.first_name = first_name
    • self.last_name = last_name
    • self.grades = grades
    • 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 sum(self.grades) / len(self.grades)
    • @property
    • def basic_grades(self):
    • return (('A', 90), ('B', 80), ('C', 70), ('D', 65))
    • def assess(self):
    • if not self.grades:
    • return None
    • avg = self.grade_average
    • for grade in self.basic_grades:
    • if avg >= grade[1]:
    • return grade[0]
    • return 'F'
    • if avg >= 90:
    • return 'A'
    • elif avg >= 80:
    • return 'B'
    • elif avg >= 70:
    • return 'C'
    • elif avg >= 65:
    • return 'D'
    • else:
    • return 'F'
    • def add_random_grade(self):
    • random_grade = choice(range(1, 11))
    • self.grades.append(random_grade)