Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab, you complete a partially prewritten Python program that uses a list. The program prompts the user to interactively enter eight batting averages,

In this lab, you complete a 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

Make sure the file BattingAverage.py is selected and open.

Write the Python statements as indicated by the comments.

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.

# Declare a named constant for array size here. MAX_AVERAGES = 8

# Declare array here.

# Write a 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 a 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.

image text in transcribed

image text in transcribed

Lists BattingAverage.py 1 Declare a naned constant for array stze here 21 MAX-AVERAGES 8 Summary In this lab, you complete a partial prewritten Python program that uses a list. 6/# rite a loop to get batting averages from user and assign to array 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 providedi tor lab includes the input staiemens some variable declarations. Comm are included in the file to help you wt the remainder of the program. 8 aver ageString - tnput("Enter a batting average:1) 9 battingAverage - float(averageString) 10: # Assign value to array. 12| # Assign the first element tn the array to be the rintnum and the naxinum ninAverage -averages[] r Start out your total with the value of the First elenent tn the 16 total " averages[) 7: # Hrite a loop here to access array values starting with Instructions

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions