122k views
1 vote
Write a function that computes the average of a list of numbers. The function will take in

one argument (the list of numbers) and it will output the average. Define the function

then call the function using the list below.

test_list = [1234, 2343, 5422, 1000, 9984, 7684]

#TODO Make function to compute average

#TODO Call the function with the test_list

1 Answer

2 votes

Final answer:

To compute the average of a list of numbers in Python, create a function that takes in the list as an argument and returns the average.

Step-by-step explanation:

Python Function to Calculate Average

To compute the average of a list of numbers in Python, you can create a function that takes in the list as an argument and returns the average.

def compute_average(numbers):
total = sum(numbers)
average = total / len(numbers)
return average

Here, the sum() function is used to calculate the sum of all the numbers in the list. Then, the average is found by dividing the total sum by the length of the list using the len() function.

Calling the Function

To call the function with the provided test_list:

test_list = [1234, 2343, 5422, 1000, 9984, 7684]
average = compute_average(test_list)
print(average)

User ChenLee
by
7.9k points