Feedback

Chat Icon

Building with GitHub Copilot

From Autocomplete to Autonomous Agents

Smart Inline Completions: Use Cases, Examples, and Exercises
36%

Error Handling and Problem Solving

When you encounter an error in your code, especially when you don't understand the error message, you can use Copilot to help you understand the error and suggest a solution.

For the sake of this example, let's consider the following code that raises an error:

def calculate_inverse(x):
    return 1 / x

def process_element(index, data):
    element = data[index]
    return calculate_inverse(element)

def results():
    data = [1, 2, 3, '4', 5]
    results = []
    for i in range(len(data)):
        result = process_element(i, data)
        results.append(result)
    return results

if __name__ == "__main__":
    print(results())

The code above calculates the inverse of each element in a list. For example, if the list is [1, 2, 10], the output should be [1, 0.5, 0.1]. However, the interpreter raises an error when it tries to calculate the inverse of the element '4'. You can use the following prompt to ask Copilot about the error:

Building with GitHub Copilot

From Autocomplete to Autonomous Agents

Enroll now to unlock all content and receive all future updates for free.