Skip to content

Commit a9339aa

Browse files
authored
Merge pull request mouredev#4674 from MarcosE-FerretoE/reto-09-Python
#9 - Python
2 parents fae574e + 5736b37 commit a9339aa

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""
2+
Ejercicio
3+
"""
4+
5+
6+
# Superclase
7+
class Animal:
8+
def __init__(self, name: str):
9+
self.name = name
10+
11+
def sound(self):
12+
pass
13+
14+
15+
# Subclases
16+
class Dog(Animal):
17+
def sound(self):
18+
print("Guau")
19+
20+
21+
class Cat(Animal):
22+
def sound(self):
23+
print("Miau")
24+
25+
26+
def print_sound(animal: Animal):
27+
animal.sound()
28+
29+
30+
my_animal = Animal("Animal")
31+
print_sound(my_animal)
32+
my_dog = Dog("Perro")
33+
print_sound(my_dog)
34+
my_cat = Cat("Gato")
35+
print_sound(my_cat)
36+
37+
"""
38+
Extra
39+
"""
40+
41+
42+
class Employee:
43+
def __init__(self, id: int, name: str):
44+
self.id = id
45+
self.name = name
46+
self.employees = []
47+
48+
def add_employee(self, employee):
49+
self.employees.append(employee)
50+
51+
def print_employees(self):
52+
for employee in self.employees:
53+
print(employee.name)
54+
55+
56+
class Manager(Employee):
57+
58+
def equipment_supervision(self):
59+
print(f"{self.name} supervises and manages teams and resources")
60+
61+
62+
class ProjectManager(Employee):
63+
64+
def __init__(self, id: int, name: str, project: str):
65+
super().__init__(id, name)
66+
self.project = project
67+
68+
def control_projects(self):
69+
print(f"{self.name} plans, executes and controls projects with {self.project}")
70+
71+
72+
class Programmer(Employee):
73+
def __init__(self, id: int, name: str, language: str):
74+
super().__init__(id, name)
75+
self.language = language
76+
77+
def code(self):
78+
print(f"{self.name} está programando en {self.language}")
79+
80+
def add_employee(self, employee: Employee):
81+
print(f"{employee.name} no tiene cargos")
82+
83+
84+
my_manager = Manager(
85+
1,
86+
"Marcos",
87+
)
88+
my_project_manager = ProjectManager(
89+
2,
90+
"Pedro",
91+
"Proyecto 1",
92+
)
93+
my_project_manager2 = ProjectManager(
94+
3,
95+
"Pepe",
96+
"Proyecto 2",
97+
)
98+
99+
my_programmer = Programmer(4, "Raul", "Python")
100+
my_programmer2 = Programmer(5, "Bruno", "Java")
101+
my_programmer3 = Programmer(6, "Ana", "Python")
102+
103+
104+
my_manager.add_employee(my_project_manager)
105+
my_manager.add_employee(my_project_manager2)
106+
107+
my_project_manager.add_employee(my_programmer)
108+
109+
my_programmer2.code()
110+
111+
my_manager.print_employees()

0 commit comments

Comments
 (0)