Read the figures from the Python text file to find the sum and the mean.

Asked 2 years ago, Updated 2 years ago, 40 views

inFp = None
outFp = None

inFp = open('data.txt', 'r')
outFp = open('output.txt', 'w')

score = inFp.readlines()
score = list(map(float, score))
scoresum = 0

for i in score :
    scoresum = scoresum + i
average = scoresum / len(score)

I'm wondering what to do from here.
You can't fix it many times.

python text file

2022-09-20 21:55

1 Answers

You made a good code for calculating the total and average. If the problem is printing the results in the output.txt file, in the last line of the program,

print('total = {}\nMean = {}'.format(scoresum, average), file=outFp)

Try adding it.


2022-09-20 21:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.