DEV Community

Cover image for Python: Find the Error
Scofield Idehen
Scofield Idehen

Posted on

Python: Find the Error

No ChatGPT, can you spot the error!!!

def calculate_average(numbers):
    total = sum(numbers)
    average = total / len(numbers)  # Potential error here
    return average

data = [10, 20, 30, "40", 50]  # Potential error-causing element

try:
    result = calculate_average(data)
    print("Average:", result)
except TypeError as e:
    print("Error:", e)
Enter fullscreen mode Exit fullscreen mode

If you find this article thrilling, discover extra thrilling posts like this on Learnhub Blog; we write a lot of tech-related topics from Cloud computing to Frontend Dev, Cybersecurity, AI and Blockchain. Take a look at How to Build Offline Web Applications. 

Resource

Top comments (0)