CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day09/pet.py
Views: 729
1
from abc import ABCMeta, abstractmethod
2
3
4
class Pet(object, metaclass=ABCMeta):
5
6
def __init__(self, nickname):
7
self._nickname = nickname
8
9
@abstractmethod
10
def make_voice(self):
11
pass
12
13
14
class Dog(Pet):
15
16
def make_voice(self):
17
print('%s: 汪汪汪...' % self._nickname)
18
19
20
class Cat(Pet):
21
22
def make_voice(self):
23
print('%s: 喵...喵...' % self._nickname)
24
25
26
def main():
27
pets = [Dog('旺财'), Cat('凯蒂'), Dog('大黄')]
28
for pet in pets:
29
pet.make_voice()
30
31
32
if __name__ == '__main__':
33
main()
34
35