Python Example | Compute the Average of 5 Numbers

This python example code will show us how to compute the average of 5 numbers.

# denotes total sum of five numbers
total_sum = 0

for n in range (5):
    # take inputs
    num = float(input('Enter number: '))
    # calculate total sum of numbers
    total_sum += num

# calculate average of numbers
avg = total_sum / 5

# print average value
print('Average of numbers =', avg)

Run this code, we may get:

Enter number: 10
Enter number: 21
Enter number: 14
Enter number: 58
Enter number: 43
Average of numbers = 29.2