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.

Program:

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.

Input/Output:

Input;

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

Output:

Average: 30.0

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this python tutorial, you will learn how to Display Prime Numbers Between Two Intervals using the if and else...
In this python tutorial, you will learn how to Calculate Standard Deviation with built in functions of the python programming...
In this Python program, we will convert temperature values from Celsius to Fahrenheit. The Celsius and Fahrenheit scales are two...