Posts

Showing posts with the label Average

Python Program To Print Average

Image
  In this post, we are going to write a python program to print get the input of data from the user and print its average. General Idea : The average of a set of data is the sum of the data and divided by the total number of data. Pre-Requisites  : Python Basics For loop Program : n=int(input("Enter the  total number of numbers")) sum1=0 for i in range(0,n):     x=int(input("Enter number "))     sum1=sum1+x print("The Average is ",sum1/n) Explanation : 1.First we are inputting the total number of data and storing that to variable 'n'. (Here in this case total number of numbers)  2. Here we are initializing the variable (identifier) sum1 to 0, which would be used to find the sum of the data. 3. Here we are using for loop to input the data and find its sum. The start value is 0. The end value of the loop is n. That means it stops at n-1. The step value is 1 by default. Therefore the loop repeats n times. 4. This statement is written under the for lo...