作业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