【拉勾二期】python 实战(二)作业贴

课后作业:自己写一个面向对象的例子

  • 描述:

创建一个类(Animal)【动物类】,类里有属性(名称,颜色,年龄,性别),类方法(会叫,会跑)

  • 创建子类【猫】,继承【动物类】,

    - 复写父类的__init__方法,继承父类的属性,
    
    - 添加一个新的属性,毛发=短毛,
    
    - 添加一个新的方法, 会捉老鼠,
    
    - 复写父类的‘【会叫】的方法,改成【喵喵叫】
    
  • 创建子类【狗】,继承【动物类】,

    - 复写父类的__init__方法,继承父类的属性,
    
    - 添加一个新的属性,毛发=长毛,
    
    - 添加一个新的方法, 会看家,
    
    - 复写父类的【会叫】的方法,改成【汪汪叫】
    
  • 创建一个猫猫实例

    - 调用捉老鼠的方法
    
    - 打印【猫猫的姓名,颜色,年龄,性别,毛发,捉到了老鼠】。
    
  • 创建一个狗狗实例

    - 调用【会看家】的方法
    
    - 打印【狗狗的姓名,颜色,年龄,性别,毛发】。
    

4、使用 yaml 来管理实例的属性

5、提交代码到自己的github仓库, 贴到作业贴上

作业3:

# -*- encoding: UTF-8 -*-
"""
@File    : workthree.py
@Time    : 2020-6-3 14:08
@Author  : Mokwing
@Email   : 1010326277@qq.com
@Software: PyCharm
@Message : 
"""

class Animal:
    # 该 Animal 类拥有的属性
    def __init__(self, name, color, age, sex):
        self.name = name
        self.color = color
        self.age = age
        self.sex = sex

    def call(self):
        print("this animal can call.")

    def run(self):
        print("this animal can run.")


class Cat(Animal):
    def __init__(self, name, color, age, sex, hair="short hair"):
        self.name = name
        self.color = color
        self.age = age
        self.sex = sex
        self.hair = hair

    def call(self):
        print("this cat can miaomiao.")

    def work(self):
        print("this cat can catch mice.")

class Dog(Animal):
    def __init__(self, name, color, age, sex, hair="long hair"):
        self.name = name
        self.color = color
        self.age = age
        self.sex = sex
        self.hair = hair

    def call(self):
        print("this cat can wangwang.")

    def work(self):
        print("this dog can watch the house.")


if __name__ == '__main__':
    cat = Cat("nico", "white", "two", "f",)
    cat.work()
    print(f"{cat.name} {cat.color} {cat.hair} {cat.age} {cat.sex} catch mice success.")

    dog = Dog("kzi", "yellow", "3", "m")
    dog.work()
    print(f"{dog.name} {dog.color} {dog.age} {dog.sex} {dog.hair}")

作业4:

https://github.com/Mokwing/mokwing2py/tree/master/hogwarts

https://github.com/hollyXM/Lagou2Project.git

廖彬面向对象作业

https://github.com/liaobin916/pythonCode.git

animail.py

(https://github.com/wzz2019/mystudynote/blob/master/pythoncode/task_0604/Animal.py)

马杰雄 第二次作业:https://github.com/majiexiong1997/study_test/tree/master/pythoncode 补交yaml数据读取

lagou_1.py
https://github.com/Staupo/Lagou2QiProject.git

张涛 实战二作业
https://github.com/tzhang-web/pyzt1

打印这些属性信息,可以在类里定义一个方法来获取。

李国彬 实战二作业
https://github.com/liguob/animal.git

https://github.com/tanya931117/TestDev/tree/master/pythoncode

https://github.com/Cat-Zhou/First_trial.git

https://github.com/jb5881/TestDevlopProject/tree/master/homework0606

王亚楠python实战二作业
https://github.com/Bella-hz/Myhomework

https://github.com/yhforthefreedom/LaGouQ2_study

python实战二作业_张志格
https://github.com/github-zhi/demo_20200606

python实战作业(二)_叶婷
https://github.com/Sunshine-Mia/PythonCode/tree/master/Work2

python实战作业(二)_林遵明 地址:pythoncode/homework
https://github.com/jimmylinz/LagouProject.git

张成作业二
https://github.com/HuaXiChen/Hogwarts_huaxichen/blob/master/pythoncode/homework/homework2