定义学生信息类

class Student():
    def __init__(self, name, score):
        self.name = name
        self.score = score

    def print_grade(self):
        if self.score >= 90:
            print(f'学员姓名:{self.name},学员成绩:{self.score},优秀')
        elif self.score >= 80:
            print(f'学员姓名:{self.name},学员成绩:{self.score},良好')
        elif self.score >= 70:
            print(f'学员姓名:{self.name},学员成绩:{self.score},中等')
        elif self.score >= 60:
            print(f'学员姓名:{self.name},学员成绩:{self.score},及格')
        else:
            print(f'学员姓名:{self.name},学员成绩:{self.score},不及格')

tom = Student('Tom', 80)
tom.print_grade()

jennifier = Student('jennifier', 59)
jennifier.print_grade()

上一篇:Python 坦克大战


下一篇:Python基础知识3: if判断语句