Implementing Abstract Base Classes
Now that you've built the Company abstract base class, it can be used as a "blueprint" for different companies. You'll practice doing just this by creating a Technology class.
The Company class from the previous exercises has been defined for you, and looks like this:
class Company(ABC):
@abstractmethod
def create_budget(self):
pass
def hire_employee(self, name):
print(f"Welcome to the team, {name}!")
Cet exercice fait partie du cours
Intermediate Object-Oriented Programming in Python
Instructions
- Create a
Technologyclass that inherits from theCompanyabstract base class. - Define the
create_budget()method with two parameters,yearandexpenses. - Create an instance of the
Technologyclass with name "Tina's Tech Advisors". - Call the
create_budget()method using the provided arguments; observe the output of this method, as well ashire_employee().
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Create a class with the name "Technology"
class ____(____):
def __init__(self, name):
self.name = name
# Define a create_budget() method
def ____(self, ____, ____):
for expense, amount in expenses.items():
print(f"{year} budget for {expense} is {amount}")
# Create an instance of the Technology class, call methods
t = ____("____")
t.____(2024, {"Salaries": 10000, "Supplies": 500})
t.____("Christian")