1. 学习
  2. /
  3. 课程
  4. /
  5. Intermediate Object-Oriented Programming in Python

Connected

练习

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

说明 1 / 共 2 个

undefined XP
    1
    2
  • Create a Bakery class that implements the Business interface; do not yet define the sell_product() method.
  • Attempt to create an instance of the Bakery class in a try-except block; observe the exception that is thrown.