-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPetsEverywhere.py
73 lines (49 loc) · 1.48 KB
/
PetsEverywhere.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Pets():
animals = []
def __init__(self, animals):
self.animals = animals
def walk(self):
for animal in self.animals:
print(animal.walk())
class Cat():
is_lazy = True
def __init__(self, name, age):
self.name = name
self.age = age
def walk(self):
return f'{self.name} is just walking around'
class Simon(Cat):
def sing(self, sounds):
return f'{sounds}'
class Sally(Cat):
def sing(self, sounds):
return f'{sounds}'
class Kelly(Cat):
def sing(self, sounds):
return f'{sounds}'
# 1 Add another Cat
# Done
# 2 Create a list of all of the pets (create 3 cat instances from the above)
# my_cats = []
simon = Cat('Simon', 3)
sally = Cat('Sally', 2)
kelly = Cat('Kelly', 4)
my_cats = [simon, sally, kelly]
# Done
# 3 Instantiate the Pet class with all your cats use variable my_pets
for cat in my_cats:
my_pets = cat
print(my_pets.walk())
# Done
# 4 Output all of the cats walking using the my_pets instance
# Done
# 1 Add another Cat
class Suzy(Cat):
def sing(self, sounds):
return f'{sounds}'
# 2 Create a list of all of the pets (create 3 cat instances from the above)
my_cats = [Simon('Simon', 4), Sally('Sally', 21), Suzy('Suzy', 1)]
# 3 Instantiate the Pet class with all your cats
my_pets = Pets(my_cats)
# 4 Output all of the cats singing using the my_pets instance
my_pets.walk()