Average of Given Numbers in Python

We will use a list to save numbers and will find the average of given numbers in the list. We know that to find the average of numbers, we simply divide the sum of all numbers by the count of all numbers. For example, to find the average of 2, 3, 4, and 5, we will simply add them(2+3+4+5 = 14) and simply divide them with 4(14÷4 = 3.5). Now let’s convert the whole process to find the average of the given numbers with Python Code.

1. Python Code to find the average of given numbers using built-in methods

numbers = [1, 2, 3, 4]
total = sum(numbers)
average = total/len(numbers)
print(average)

Output:

2.5

2. Python Code to find the average of given numbers using for loop

numbers = [1, 2, 3, 4]
total = 0
count=0
for i in numbers:
    total = total + i
    count = count + 1
average = total/count
print(average)

Output:

2.5

Also Read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you