183k views
1 vote
I need the answer for Edhesive Question 9.7 Question 4

User Antero
by
4.5k points

1 Answer

7 votes

Answer:

Question is incomplete here.

Question 4 Using the prices.txt data file find the average of the values in the file

I assume that you have a file prices.txt and it is having floating numbers separated by new line.

for ex :

$ cat prices.txt

110.29

239.10

243.19

435.22

765.98

987.76

765

876.09

So we need to find the average and it should match when we caluculate through calculator or XL sheet average.

Answer :

Below Python code will accurately prints the average of above prices.txt file

infile = open('prices.txt', 'r')

lines = infile.readlines()

infile.close()

mean = 0

for line in lines:

number = float(line)

mean=mean+number

mean=mean/len(lines)

print (mean)

Step-by-step explanation:

Result is : 552.82

User Steven Huwig
by
5.0k points