BaşlayınÜcretsiz Başlayın

FinancialCalculator

Let's extend the BasicCalculator class and create the FinancialCalculator.

To start, you'll create this child class with minimal functionality - the ability to calculate the monthly interest rate from the annual interest rate. Later, you will add more features to the FinancialCalculator!

numpy has been imported as np for you.

Bu egzersiz

Case Study: Building Software in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create the class FinancialCalculator by inheriting from BasicCalculator.
  • Create an instance of the FinancialCalculator class as financial_calculator.
  • Use financial_calculator to compute the monthly interest rate given an annual interest rate of 6%, remembering to input the percentage as a decimal.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

class BasicCalculator():
  def divide(self, x, y):
    return x / y

# Create a class FinancialCalculator that inherits from BasicCalculator
class FinancialCalculator(____):
  def calculate_monthly_interest_rate(self, annual_interest_rate):
    return self.divide(annual_interest_rate, 12) 

# Create a financial calculator
financial_calculator = ____()

# Print the monthly interest rate for a yearly rate of 6 percent
print(financial_calculator.calculate_monthly_interest_rate(____))
Kodu Düzenle ve Çalıştır