# Program of Average of two Numbers in Python #6

Share with others

## Program of Average of two Numbers in Python

Program of Average of two Numbers in Python

Average means arithmetic mean which can be calculated by the following formula

Average = Sum of all numbers/ Total numbers

for example: if we have to calculate the average of 3 and 7, so average of these numbers can be calculated as follows:

average = (3 + 7)/2

average = 5.0

Since the total numbers are two so we divided the sum of all the numbers by 2.

for example: if we have to calculate the average of 3, 6 and 9, so average of these numbers can be calculated as follows:

average = (3+6+9)/3

average = 6.0

Since the total numbers are three so we divided the sum of all the numbers by 3.

Suppose we have to calculate the average of 5, 10, 20, 15 and 10, so average of these numbers can be calculated as follows:

average = (5 + 10 + 20 + 15 + 10)/5

average = 12.0

Since the total numbers are five so we divided the sum of all the numbers by five.

## Write a program in python to calculate the average of two numbers (integers).

```num1 = int(input("Enter first number : ")) #Accepting first integer from user
num2 = int(input("Enter second number : "))#Accepting second integer from user
avrg = (num1 + num2)/2 #Calculating average
print("Average of two numbers is : ", avrg)#Displaying the average```

### Line by Line explanation of above code

1. First line of code is for accepting a number(integer) from the user.
2. Second line of code is for accepting another number(integer) from the user.
3. In third line, we are calculating the average by adding both numbers and divided by 2. Result of average is stored in a variable “avrg” (You can take any other variable name)
4. Fourth Line is simply printing the result.

OUTPUT

### Similarly we can also calculate the average of two floating point numbers

```num1 = float(input("Enter first number : ")) #Accepting first from user
num2 = float(input("Enter second number : "))#Accepting second from user
avrg = (num1 + num2)/2 #Calculating average
print("Average of two numbers is : ", avrg)#Displaying the average```

OUTPUT

NOTE: We can accept either integer or floating numbers from user

## Write a program in python to calculate the average of three numbers.

```num1 = int(input("Enter first number : ")) #Accepting first integer from user
num2 = int(input("Enter second number : "))#Accepting second integer from user
num3 = int(input("Enter third number : "))
avrg = (num1 + num2 + num3)/3 #Calculating average
print("Average of three numbers is : ", avrg)#Displaying the average```

OUTPUT

## MCQ of Computer Science Chapter Wise

1. Functions in Python

2. Flow of Control (Loop and Conditional statement)

3. 140+ MCQ on Introduction to Python

4. 120 MCQ on String in Python

5. 100+ MCQ on List in Python

6. 50+ MCQ on Tuple in Python

7. 100+ MCQ on Flow of Control in Python

8. 60+ MCQ on Dictionary in Python

## 70 Practice Questions on if-else

Disclaimer : I tried to give you the correct coding of ” Average of two numbers in Python” , but if you feel that there is/are mistakes in the code or explanation of “Average of two numbers in Python  “ given above, you can directly contact me at csiplearninghub@gmail.com.

Share with others

### 1 thought on “Program of Average of two Numbers in Python #6”

1. Awesome! Its genuinely remarkable post, I have got much clear idea regarding from this post