day15作业

2018-08-02  本文已影响0人  七夜_174e

1定义一个学生类,属性:名字,年龄,成绩(语文,数学,英语)(每科成绩的类型为整数)。方法:a、获取学生的姓名 b、获取学生年龄 c、返回3门科目中最高的分数。

class Student:
    def __init__(self, name='', age=0, score1=0, score2=0, score3=0):
        score = {'语文': score1, '数学': score2, '英语': score3}
        self.name = name
        self.age = age
        self.score = score

    def get_name(self):
        print('该生姓名:%s' % self.name)

    def get_age(self):
        print('该生年龄:%s' % self.age)

    def get_course(self):
        # ???????????
        max_score = max(v for i, v in self.score.items())
        print(self.score.items(),  max_score)

if __name__ == '__main__':
    student = Student(score1=98, score2=100, score3=199)

    student.get_age()
    student.get_name()
    student.get_course()

dict_items([('语文', 98), ('数学', 100), ('英语', 199)]) 199
TIM截图20180802210244.png
class User:
    def __init__(self, first_name, last_name):
        self.first_name = first_name
        self.last_name = last_name
        self.brief = ''

    def descibe_user(self):
        print(self.first_name + ' '+self.last_name)

    def greet_user(self):
        print('早上好,%s %s' % (self.first_name, self.last_name))


class Admin(User):
    def __init__(self, first_name, last_name):
        super().__init__(first_name, last_name)
        self.privileges = ['can add post', 'can delete post', 'can ban user']

    def show_privileges(self):
        print(*self.privileges)


if __name__ == '__main__':
    # student = Student(score1=98, score2=100, score3=199)
    admin = Admin('alan', 'PT')
    admin.show_privileges()
上一篇下一篇

猜你喜欢

热点阅读