ComeçarComece de graça

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.

Este exercício faz parte do curso

Case Study: Building Software in Python

Ver curso

Instruções do exercício

  • Use the proper variable name for the class. Choose from mortgage_calculator or MortgageCalculator?
  • Use the proper variable name for the function. Choose from calculate_monthly_payment or CalculateMonthlyPayment?

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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
Editar e executar o código