Question
Answered step-by-step

In this lab, complete partially prewritten Python program that uses...

In this lab, complete partially prewritten Python program that uses a list.

The program prompts the user to interactively enter eight batting averages, which the program stores in an array. It should then find the minimum and maximum batting averages stored in the array, as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help you write the remainder of the program.

Instructions

  1. Make sure the file BattingAverage.py is selected and open.
  2. Write the Python statements as indicated by the comments.
  3. Execute the program by clicking the Run button at the bottom of the screen. Enter the following batting averages: .299, .157, .242, .203, .198, .333, .270, .190. The minimum batting average should be .157 and the maximum batting average should be .333. The average should be .2365.


Given Code:


# Declare a named constant for array size here.

MAX_AVERAGES = 8

# Declare array here.

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

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

   battingAverage = float(averageString)

   # Assign value to array.

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

minAverage = averages[0]

maxAverage = averages[0]

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

total = averages[0]

# Write loop here to access array values starting with averages[1]

   # Within the loop test for minimum and maximum batting averages.


   # Also accumulate a total of all batting averages.


# Calculate the average of the 8 batting averages.


# Print the batting averages stored in the averages array.


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




Attempted Code:


# 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)

    averages.append(battingAverage)

    # Assign value to array.


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

minAverage= averages[0]

maxAverage= averages[0]

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

total = averages[0]

# Write a loop here to access array values starting with averages[1]

average = 0

    # Within the loop test for minimum and maximum batting averages.

for i in range(1, MAX_AVERAGES):

    if average < minAverage:

        minAverage = averages[i]

        print("Minimum batting average is: " + str(minAverage))

    if average > maxAverage: 

        maxAverage = averages[i]

        print("Maximum batting average is: " + str(maxAverage))

    else:

        print("Minimum batting average is: " + str(minAverage))


        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.

Avg= 0

print(Avg)



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


print("Average batting average is: " + str(average))



Please I need help in making this code work I have the code down, but it does not produce the Maximum output, only displays the minimum several times, but it does display the correct average batting. If possible could I see the correct code for this way. Thanks

Answer & Explanation
Verified Solved by verified expert
Rated Helpful
<p>ipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor</p> Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet

Unlock full access to Course Hero

Explore over 16 million step-by-step answers from our library

Subscribe to view answer

onsequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pe

Step-by-step explanation

llentesque dapibus efficitur laoree

ur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam laci

s ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. D

icitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit

ipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Na

Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipi


or nec facilisis. Pellentesque dapibus efficitur

batting.JPG


ec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapib

1 Attachment
batting.JPG
JPG