【小白学编程Python方向】项目练习第6期(参考答案)
参考答案:
class Animal:
def eat(self):
print "%s eat " %self.name
def drink(self):
print "%s drink " %self.name
def shit(self):
print "%s shit " %self.name
def pee(self):
print "%s pee " %self.name
class Cat(Animal):
def __init__(self, name):
self.name = name
self.breed='cat'
def cry(self):
print 'miaomiao'
class Dog(Animal):
def __init__(self, name):
self.name = name
self.breed='dog'
def cry(self):
print 'wangwang'
# #########执行#########
c1 = Cat('the cat of white ')
c1.eat()
c2 = Cat('the cat of black ')
c2.drink()
d1 = Dog('the little dog ')
d1.eat()
Tips:
小白学编程-Python方向:【牛客带你学编程】【Python方向】0基础小白入门培养计划
查看15道真题和解析