# What is the total and average of 4, 6, 8, 5, 7?

What is the total and average of 4, 6, 8, 5, 7?

## This Post Has 4 Comments

1. neisha2507 says:

See explaination

Explanation:

 Declare a named constant for array size here.

MAX_AVERAGES = 8

Declare array here.

averages = []

 Write a loop to get batting averages from user and assign to array.

for i in range(MAX_AVERAGES):

averageString = input("Enter a batting average: ")

battingAverage = float(averageString)

Assign value to array.

averages.append(battingAverage)

 Assign the first element in the array to be the minimum and the maximum.

minAverage = averages

maxAverage = averages

Start out your total with the value of the first element in the array.

total = averages

 Write a loop here to access array values starting with averages

Within the loop test for minimum and maximum batting averages.

for i in range(1, MAX_AVERAGES):

if averages[i] < minAverage:

minAverage = averages[i]

if averages[i] > maxAverage:

maxAverage = averages[i]

total += averages[i]

 Also accumulate a total of all batting averages.

Calculate the average of the 8 batting averages.

average = total / MAX_AVERAGES

 Print the batting averages stored in the averages array.

for avg in averages:

print(avg)

Print the maximum batting average, minimum batting average, and average batting average.

print('Maximum batting average is ' + str(maxAverage))

print('Minimum batting average is ' + str(minAverage))

print('Average batting average is ' + str(average)

2. Expert says:

3. alystidham772 says:
4. Expert says: