शुरू करेंमुफ़्त में शुरू करें

Abstract Base Classes लागू करना

अब जब आपने Company abstract base class बना ली है, तो इसे अलग-अलग कंपनियों के लिए "ब्लूप्रिंट" की तरह इस्तेमाल किया जा सकता है. आप यही अभ्यास Technology क्लास बनाकर करेंगे.

पिछले अभ्यासों से Company क्लास आपके लिए परिभाषित है, और कुछ इस तरह दिखती है:

class Company(ABC):
  @abstractmethod
  def create_budget(self):
    pass

  def hire_employee(self, name):
    print(f"Welcome to the team, {name}!")

यह अभ्यास पाठ्यक्रम का हिस्सा है

Intermediate Object-Oriented Programming in Python

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Company abstract base class से inherit करने वाली Technology क्लास बनाएँ.
  • दो पैरामीटर्स year और expenses के साथ create_budget() method परिभाषित करें.
  • "Tina's Tech Advisors" नाम के साथ Technology क्लास का एक instance बनाएँ.
  • दिए गए arguments का उपयोग करके create_budget() method कॉल करें; इस method का आउटपुट और साथ ही hire_employee() का आउटपुट देखें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Create a class with the name "Technology"
class ____(____):
  def __init__(self, name):
    self.name = name

  # Define a create_budget() method
  def ____(self, ____, ____):
    for expense, amount in expenses.items():
      print(f"{year} budget for {expense} is {amount}")
  
# Create an instance of the Technology class, call methods
t = ____("____")
t.____(2024, {"Salaries": 10000, "Supplies": 500})
t.____("Christian")
कोड संपादित करें और चलाएँ