Using good variable names
Proper variable naming conventions improve readability, enhance maintainability, and reduce errors. Use proper naming conventions to name a class and a function.
This exercise is part of the course
Case Study: Building Software in Python
Exercise instructions
- Use the proper variable name for the class. Choose from
mortgage_calculator
orMortgageCalculator
? - Use the proper variable name for the function. Choose from
calculate_monthly_payment
orCalculateMonthlyPayment
?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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