Python Program to Find Average of a List

This Python program calculates the average of numbers in a given list.

Problem Statement:

Given a list of numbers, we need to find the average of those numbers.


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

# Example list of numbers
number_list = [10, 20, 30, 40, 50]

avg = calculate_average(number_list)
print("Average:", avg)

How it Works:

  1. We define a function calculate_average that takes a list of numbers as an argument.
  2. Inside the function, we calculate the sum of all numbers in the list using the sum() function.
  3. We then calculate the average by dividing the total sum by the number of elements in the list (len(numbers)).
  4. The calculated average is returned from the function.
  5. An example list number_list is provided, and the calculate_average function is called with this list.
  6. The calculated average is printed to the console.



number_list = [10, 20, 30, 40, 50]


Average: 30.0