2019-01-14 day16 作业

0.定义一个学生类。有属性:姓名、年龄、成绩(语文,数学,英语)[每课成绩的类型为整数]

方法:

a. 获取学生的姓名:getname()

b. 获取学生的年龄:getage()

c. 返回3门科目中最高的分数。get_course()

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

    def getname(self):
        print('学生姓名:%s' % self.name)

    def getage(self):
        print('学生年龄:%s' % self.age)


def main():
    stu1 = Student('王月䜣熙', 12, score=[95,99,98])
    stu1.getname()
    stu1.getage()
    print(max(stu1.score))

1.建立一个汽车类Auto,包括轮胎个数,汽车颜色,车身重量,速度等成员变量,并通过不同的构造方法创建实例。

至少要求 汽车能够加速 减速 停车。

再定义一个小汽车类CarAuto 继承Auto 并添加空调、CD等成员变量 覆盖加速 减速的方法

class Auto:
    def __init__(self, tire, color, weight, speed):
        self.tire = tire
        self.color = color
        self.weight = weight
        self.speed = speed


    def speed_up2(self):
        print('对象方法!现在是加速!')

    def speed_cut2(self):
        print('对象方法!现在是减速!')

    def stop2(self):
        print('对象方法!现在是停车!')


    @staticmethod
    def speed_up():
        print('静态方法!现在是加速!')

    @staticmethod
    def speed_cut():
        print('静态方法!现在是减速!')

    @staticmethod
    def stop():
        print('静态方法!现在是停车!')

    @classmethod
    def speed_up1(cls):
        print('类方法!现在是加速!')
    @classmethod
    def speed_cut1(cls):
        print('类方法!现在是减速!')
    @classmethod
    def stop1(cls):
        print('类方法!现在是停车!')


class CarAuto(Auto):
    def __init__(self, tire, color, weight, speed, meidi, CD):
        super().__init__(tire, color, weight, speed)
        self.meidi = meidi
        self.CD = CD

    def mei_di(self):
        print('空调!')

    def C_D(self):
        print('CD')


def main():
    car1 = Auto(4, '白色', '500kg', '120km/h')
    car1.speed_up2()
    car1.speed_cut2()
    car1.stop2()

    Auto.speed_cut()
    Auto.speed_up()
    Auto.stop()

    Auto.speed_cut1()
    Auto.speed_up1()
    Auto.stop1()

    c1 = CarAuto(4, '白色', '500kg', '100km/h', 'haier', 'zjl')
    c1.mei_di()
    c1.C_D()

你可能感兴趣的:(2019-01-14 day16 作业)