LoslegenKostenlos loslegen

Implementing a formal interface with ABC

In this exercise, you'll practice implementing a formal interface created using the ABC class and the @abstractmethod decorator. The Business interface has been created for you, and is shown below. Good luck!

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

Diese Übung ist Teil des Kurses

Intermediate Object-Oriented Programming in Python

Kurs anzeigen

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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(____)
Code bearbeiten und ausführen