40 lines
752 B
Python
40 lines
752 B
Python
|
class Pet:
|
||
|
def __init__(self,name,age):
|
||
|
self.name = name
|
||
|
self.age = age
|
||
|
|
||
|
def show(self):
|
||
|
print(f"I am {self.name} and I am {self.age} years old")
|
||
|
|
||
|
def speak(self):
|
||
|
print('I do not know what I say')
|
||
|
|
||
|
class Cat(Pet):
|
||
|
def __init__(self, name, age, color):
|
||
|
super().__init__(name, age)
|
||
|
self.color = color
|
||
|
|
||
|
def speak(self):
|
||
|
print("miaou")
|
||
|
|
||
|
def show(self):
|
||
|
print(f"I am {self.name} and I am {self.age} years old and I'm {self.color}")
|
||
|
|
||
|
class Dog(Pet):
|
||
|
def speak(self):
|
||
|
print("bark")
|
||
|
|
||
|
class Fish(Pet):
|
||
|
pass
|
||
|
|
||
|
p = Pet('Tim', 19)
|
||
|
p.show()
|
||
|
c = Cat('Billy', 34, 'blue')
|
||
|
c.show()
|
||
|
c.speak()
|
||
|
d = Dog('Jill', 25)
|
||
|
d.show()
|
||
|
d.speak()
|
||
|
f = Fish('Tonton', 14)
|
||
|
f.speak()
|