Discuss / Python / 作业

作业

Topic source

EddieLau_

#1 Created at ... [Delete] [Delete and Lock User]
class Student(object):
    def __init__(self, name, score):
        self.name = name
        self.score = score

    def get_grade(self):
        if not isinstance(self.score, int): raise ValueError('invalidate score!')

        if self.score > 100 or self.score < 0:
            raise ValueError('invalidate score! score value between "0" and "100".')

        if self.score >= 80:
            return 'A'
        if self.score >= 60:
            return 'B'
        return 'C'


  • 1

Reply