ÎncepețiÎncepe gratuit

Implementarea unei interfețe formale cu ABC

În acest exercițiu, vei exersa implementarea unei interfețe formale create cu clasa ABC și decoratorul @abstractmethod. Interfața Business a fost deja creată pentru tine și este prezentată mai jos. Succes!

class Business(ABC):
  @abstractmethod
  def sell_product(self, product_name, price, quantity):
    pass

Acest exercițiu face parte din cursul

Programare orientată pe obiecte intermediară în Python

Vezi cursul

Exercițiu interactiv practic

Încearcă acest exercițiu completând acest cod de exemplu.

# Create a class that inherits the Business interface
class ____(____):
  def __init__(self, business_name):
    self.business_name = business_name

# Attempt to create a Bakery object, observe the exception
____:
  blue_eyed_baker = ____("Blue Eyed Baker")
____ Exception ____ e:
  print(____)
Editează și rulează codul