Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im stuck in the middle of this program. I got the beginning and end working. It prints the averages all in one line with single

Im stuck in the middle of this program. I got the beginning and end working. It prints the averages all in one line with single space between and it prints the min, max and average. But I can't get it to print the averages position in the array Below is what I need the results to show. Below that, is my current code. Thank you.
****************************************************************
Enter a batting average: .299
Enter a batting average: .157
Enter a batting average: .242
Enter a batting average: .203
Enter a batting average: .198
Enter a batting average: .333
Enter a batting average: .270
Enter a batting average: .190
averages[0] is: 0.299
averages[1] is: 0.157
averages[2] is: 0.242
averages[3] is: 0.203
averages[4] is: 0.198
averages[5] is: 0.333
averages[6] is: 0.27
averages[7] is: 0.19
Minimum batting average is 0.157
Maximum batting average is 0.333
Average batting average is 0.2365
****************************************************************
# Initialize an integer for list size here.
numAverages =8
# Initialize list here.
averages =[]
# Write a loop to get batting averages from user and add to list.
for i in range(8):
# String version of batting average input by user.
averageString = input("Enter a batting average: ")
# Use this variable to store the batting average input by user.
battingAverage = float(averageString)
# add value to list.
averages.append(battingAverage)
# Use these variables to store the minimim and maximum batting averages.
minAverage = min(averages)
maxAverage = max(averages)
total_average = sum(averages)
# Assign the first element in the list to be the minimum and the maximum.
min = averages[0]
max = averages[0]
# Start out your total initialized to 0.
total =0
# Write a loop here to access list values starting with averages[1]
for i in range(1,len(averages)):
# Within the loop test for minimum and maximum batting averages.
if averages[i]< minAverage:
minAverage = averages[i]
if averages[i]> maxAverage:
maxAverage = averages[i]
# Also accumulate a total of all batting averages.
total += averages[i]
# Calculate the average of the 8 averages.
average = total/8
# Print the averages stored in the averages list.
print("averages",[i],"is:")
for i in averages:
print([i])
# Print the maximum batting average, minimum batting average, and average batting average.
print("
Minimum batting average:", minAverage)
print("Maximum batting average:", maxAverage)
print("Average batting average:", average)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the factors that determine the degree of decentralisation

Answered: 1 week ago

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago