FInd The Bug Challenge

Scofield Idehen - Jun 13 '23 - - Dev Community
def calculate_average(numbers):
    total = 0
    count = 0
    for number in numbers:
        total += number
        count += 1
    average = total / count
    return average

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result = calculate_average(numbers)
print(f"The average is: {result}")
Enter fullscreen mode Exit fullscreen mode

Explanation

The code defines a function called calculate_average that takes a list of numbers as input. It initializes total and count variables to zero. Then, it iterates over the numbers in the list and adds each number to the total variable while incrementing the count by 1.

After the loop, the average is calculated by dividing the total by the count. Finally, the calculated average is printed to the console.

The challenge is to find a tiny mistake in the code that has a significant impact on the output. Your task is to identify and fix the bug to obtain the correct average. Good luck with the bug hunt!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player