Home » Program to find Average of Two Numbers using a Loop Python

Program to find Average of Two Numbers using a Loop Python

Learn about the Program to find the Average of Two Numbers using a Loop Python in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

Program to find Average of Two Numbers using a Loop Python

In the below program we are using a Loop to calculate the sum of numbers. Then calculate the average.

# Python program to find the average of two numbers

# variable to store total sum of numbers
total_sum = 0

for n in range (2):
    num = float(input('Enter number: '))
    total_sum += num

# calculate average
avg = total_sum / 2

# print value
print('Average of numbers = %0.2f' %avg)

Output:

Enter number: 5
Enter number: 2
Average of numbers = 3.50

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Average of Two Numbers in Python using Function