I should write a code for calculating average of some grades in a csv file. My code is going to be check by another program(and not a human.) I already have the Help file about the checking program and I should design my code to be understandable for it.
This is my code:
import csv
from statistics import mean
def calculate_averages(input_file_name, output_file_name):
with open("C:\\Users\\Tandis\\Desktop\\ggg.CSV", 'r') as f:
rows = csv.reader(f)
for row in rows:
name = row[0]
name = name.strip() + ","
scores = list()
for grade in row[1:]:
scores.append(int(grade))
average = str(mean(scores)).strip()
print(name,average)
print(calculate_averages("ggg.csv" , 'jj'))
And the output is:
mandana, 7.5
hamid, 6.066666666666666
sina, 11.285714285714286
sara, 9.75
soheila, 7.833333333333333
ali, 5
sarvin, 11.375
None
Press any key to continue . . .
But the output that checking program can understand is like:
mandana,7.5
hamid,6.066666666666666
sina,11.285714285714286
sara,9.75
soheila,7.833333333333333
ali,5.0
sarvin,11.375
I don't know how to remove the space between numbers and names in output. Any Ideas?