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

Using doctest

The doctest module provides a straightforward way to test your functions using examples included in docstrings. In this exercise, you'll have the opportunity to practice testing with the doctest module.

The doctest module has already been pre-loaded into your environment.

Bu egzersiz

Case Study: Building Software in Python

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

Egzersiz talimatları

  • In the FinancialCalculator class, calculate the monthly interest, which is the quotient of the yearly interest and the number of months in a year (12).
  • Use the relevant function from the doctest module to test your function's example code.

Remember, doctest provides only an output if the code/docs are incorrect.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

class FinancialCalculator(BasicCalculator):
    def monthly_interest(self, annual_interest_rate):
      '''
      >>> monthly_interest(0.06)
      0.005
      '''
      # Calculate the quotient of the annual_interest_rate and 12 (the number of months in a year).
      return self.divide(____, ____)

# Run doctest
____
Kodu Düzenle ve Çalıştır