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

Math calculations के लिए एक tool बनाएँ

अब अपने tool को बनाने का समय है. मान लीजिए आप एक छोटी construction कंपनी चलाते हैं और आपको छत के एक किनारे की लंबाई निकालनी है. अगर आपको उन दो बीम्स की लंबाई पता है जो छत को समकोण पर सहारा देती हैं, तो आप नीचे दिए गए hypotenuse फॉर्मूला से छत की लंबाई निकाल सकते हैं. $$c = \sqrt{a^2 + b^2}$$

Roof beam calculation diagram

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

LangChain के साथ Agentic Systems डिज़ाइन करना

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

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

  • फंक्शन को tool की तरह परिभाषित करने के लिए आवश्यक डेकोरेटर का उपयोग करें.
  • Hypotenuse पाने के लिए, input स्ट्रिंग पर .split() मेथड का उपयोग करके समकोण त्रिभुज की बाकी दो लंबाइयाँ निकालें.
  • त्रिभुज के हर किनारे a और b को फ्लोट में कन्वर्ट करें और वैल्यू से अतिरिक्त स्पेस हटाने के लिए .strip() का उपयोग करें.
  • Python के math मॉड्यूल का उपयोग करके a और b की लंबाइयों का square करें, उन्हें जोड़ें, और उनका square root निकालकर छत की कुल लंबाई पता करें.

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

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

# Define this math function as a tool
____
def hypotenuse_length(input: str) -> float:
    """Calculates the length of the hypotenuse of a right-angled triangle given the lengths of the other two sides."""
    
    # Split the input string to get the lengths of the triangle
    sides = ____.____(',')
    
    # Convert the input values to floats, removing extra spaces
    a = ____(____[0].____())
    b = ____(____[1].____())
    
    # Square each of the values, add them together, and find the square root 
    return ____.sqrt(a____2 + b____2)
कोड संपादित करें और चलाएँ