좋은 변수 이름 사용하기
적절한 변수 명명 규칙은 가독성을 높이고, 유지 보수를 개선하며, 오류를 줄여 줍니다. 올바른 명명 규칙을 적용해 클래스와 함수를 이름 지어 보세요.
이 연습은 강의의 일부입니다
케이스 스터디: Python으로 소프트웨어 만들기
연습 안내
- 클래스에는 적절한 변수 이름을 사용하세요.
mortgage_calculator와MortgageCalculator중에서 선택하세요. - 함수에는 적절한 변수 이름을 사용하세요.
calculate_monthly_payment와CalculateMonthlyPayment중에서 선택하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Use proper naming conventions for a class name
class ____(FinancialCalculator):
def __init__(self, loan_amount, annual_interest_rate, years):
super().__init__()
self.loan_amount = loan_amount
self.monthly_interest_rate = self.monthly_interest(annual_interest_rate)
self.months = self.multiply(years, 12)
# Use proper naming conventions for a function name
def ____(self):
numerator = self.monthly_interest_rate * (1 + self.monthly_interest_rate) ** self.months
denominator = (1 + self.monthly_interest_rate) ** self.months - 1
multiplier = self.divide(numerator, denominator)
monthly_payment = round(self.multiply(self.loan_amount, multiplier), 2)
return monthly_payment