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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| import abc
class Student(abc.ABC): def __init__(self, name, midterm, finalExam, assignment, usual): self.name = name self.midterm = midterm self.finalExam = finalExam self.assignment = assignment self.usual = usual @abc.abstractmethod def finalScore(self): return NotImplemented
class Student107(Student): def __init__(self, name, midterm, finalExam, assignment, usual): super(Student107, self).__init__(name, midterm, finalExam, assignment, usual) def finalScore(self): score = self.midterm * 0.25 + self.finalExam * 0.35 + self.assignment * 0.3 + self.usual * 0.1 print('{}\'s final score: {}'.format(self.name, score)) return score
Ben = Student107('Ben', 100, 100, 100, 100) XioMing = Student107('XioMing', 50, 75, 32, 85) Peter = Student107('Peter', 46, 89, 32, 90) print('107 Students:') Ben.finalScore() XioMing.finalScore() Peter.finalScore()
class Student108(Student): def __init__(self, name, midterm, finalExam, assignment, usual, addPoint): super(Student108, self).__init__(name, midterm, finalExam, assignment, usual) self.addPoint = addPoint def finalScore(self): score = self.midterm * 0.3 + self.finalExam * 0.3 + self.assignment * 0.2 + self.usual * 0.2 + self.addPoint print('{}\'s final score: {}'.format(self.name, score)) return score
Brian = Student108('Brian', 100, 100, 100, 100, 3) XioMing = Student108('XioMing', 50, 75, 32, 85, 5) Apple = Student108('Apple', 46, 89, 32, 90, 0) print('108 Students:') Brian.finalScore() XioMing.finalScore() Apple.finalScore()
|