Question: Problem PQ 4 . Modifying and Filling In Python Code. ( a ) [ 6 points ] Here are the formulas for computing the mean,

Problem PQ4. Modifying and Filling In Python Code.
(a)[6 points] Here are the formulas for computing the mean, , and standard deviation, , of a
set of n values:
=i=1nxin=x1+x2+cdots+xnn,=i=1n(xi-)2n2=i=1nxi2n-22
The following Python functions returns the mean of the values of a passed list, x, using the
formula for the mean, , given above.
def mean(x):
xsum =0
for i in range(len(x)):
xsum += x[i]
return xsum/len(x)
Write another Python function (which could call the function above) to return the standard
deviation of the values of a passed list, x. Also (for purposes of assigning partial credit),
circle the formula for the standard deviation, \sigma , that you used above.
b)[6 points] The text file autompg.dat contains 398 lines of automobile mileage data of the
following, tab-separated data (where the character | is used only to denote the tab locations):
car name | model year | number of cylinders | miles per gallon
For example, the first two lines of the file might look like:
Prius 2005455.0
Escalade 2005816.5
Add Python expressions/statements to complete the program below, which should read the
data from the file and display it to the screen. Assume car name contains no spaces.
# Open the file
input = file.open()
# name is of type str
# year and cyls are of type int
# mpg is of type float
print("Name \t Year \t # Cyls.\t MPG")
# Get input from file
for :
# within for loop body, display that line of data
print(f"{name}\t {year}\t {cyls}\t {mpg}")
# end for loop body
# Close the file
input.close()
(c)[8 points
Assume that values is a 101-element list containing measurements from a scientific
experiment, as declared in the Python code below.
Add Python statements that would complete the program below to count the number of
positive values, negative values, and zero values in the list, and (complete the code to)
write out a message summarizing how many values of each type were found.
values =[0 for i in range(101)] # LIST DECLARATION
# OTHER CODE TO INITIALIZE values WOULD BE HERE (DO NOT WRITE)
# DECLARE/INITIALIZE YOUR OTHER VARIABLES HERE
for i in :
# end for loop body
# Print statements: COMPLETE AS NECESSARY
print(f"# of positive entries: ")
print(f"# of negative entries: ")
print(f"# of zero entries: ")
Problem PQ 4 . Modifying and Filling In Python

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!