Inheritance

  • + 0 comments
    class Student(Person):
        #   Class Constructor
        #   
        #   Parameters:
        #   firstName - A string denoting the Person's first name.
        #   lastName - A string denoting the Person's last name.
        #   id - An integer denoting the Person's ID number.
        #   scores - An array of integers denoting the Person's test scores.
        #
        # Write your constructor here
        def __init__(self, firstName, lastName, idNumber, scores):
            Person.__init__(self,firstName, lastName, idNumber)
            self.scores = scores
    
    #   Function Name: calculate
    #   Return: A character denoting the grade.
    #
    # Write your function here
    def calculate(self):
        sum = 0
        for i in range(len(self.scores)):
            sum = sum + self.scores[i]
    
            avg = sum/len(self.scores)
    
        if ((90<=avg) and (avg<=100)):
            return str("O")
        elif ((80<=avg) and (avg<90)):
            return str("E")
        elif ((70<=avg) and (avg<80)):
            return str("A")
        elif ((55<=avg) and (avg<70)):
            return str("P")
        elif ((40<=avg) and (avg<55)):
            return str("D")
        else:
            return str("T")