추상 기본 클래스 구현하기
이미 Company 추상 기본 클래스를 만들었으니, 이제 서로 다른 회사들을 위한 "청사진"으로 사용할 수 있어요. 이번에는 Technology 클래스를 만들어 이를 연습해 보겠습니다.
이전 연습 문제에서 사용한 Company 클래스는 다음과 같이 정의되어 있어요:
class Company(ABC):
@abstractmethod
def create_budget(self):
pass
def hire_employee(self, name):
print(f"Welcome to the team, {name}!")
이 연습은 강의의 일부입니다
Python 중급 객체 지향 프로그래밍
연습 안내
Company추상 기본 클래스를 상속하는Technology클래스를 만드세요.- 두 개의 매개변수
year와expenses를 받는create_budget()메서드를 정의하세요. - 이름이 "Tina's Tech Advisors"인
Technology클래스의 인스턴스를 생성하세요. - 제공된 인자를 사용해
create_budget()을 호출하고, 이 메서드의 출력과hire_employee()의 출력도 확인하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# 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")