codescracker


python

Python Program to Calculate Average of Numbers



« Previous Program Next Program »


Calculate Average of Numbers in Python

To calculate average ir arithmetic mean of numbers in python, you have to ask from user to enter some set of numbers say 5 numbers to find the average of those numbers as shown in the program given here.

Python Programming Code to Calculate Average of Numbers

Following python program ask from user to enter 5 numbers to find the average of all numbers:

# Python Program - Calculate Average of Numbers

print("Enter 'x' for exit.");
print("Enter any 5 numbers to find average: ");
n1 = input();
if n1 == 'x':
    exit();
else:
    n2 = input();
    n3 = input();
    n4 = input();
    n5 = input();
    number1 = int(n1);
    number2 = int(n2);
    number3 = int(n3);
    number4 = int(n4);
    number5 = int(n5);
    sum = number1 + number2 + number3 + number4 + number5;
    average = sum/5;
    print("Average of entered 5 numbers is",average);

Here is the sample run of the above Python program shows how to calculate and print average of numbers:

calculate average of numbers python

Above is the initial output asking from the user to enter any five numbers to find average of all the given 5 numbers by users as shown in the below sample output:

find average of numbers python

Here is the same program directly written and run on python shell:

python calculate average of numbers

Program Video with Compile and Run

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test