Learn Programming and technology with ease @ developerpublish.com

HomePythonPython Program to Find Average of a List

# 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;

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

## Output:

`Average: 30.0`

### You May Also Like

#### Python Program to Remove Duplicates from a Linked List

In this Python program, we will create a singly linked list and remove duplicate elements from it. A linked list...

#### Python Program to Solve the Celebrity Problem

This Python program solves the Celebrity Problem by finding a person who is known by everyone but does not know...

#### Python Program to Solve n-Queen Problem with Recursion

This Python program uses a recursive approach to solve the n-Queens problem. It explores all possible combinations of queen placements...