I am new in python and I wanna calculate averages of grades for a student class with this:
from statistics import mean
import csv
def calculate_averages(input_file_name, output_file_name):
with open('D:\\p3\\grades.csv', 'r') as f:
f = csv.reader(f)
namelist=[]
averagelist=[]
for row in f:
name = row[0]
scores = row[1:]
scores = list(map(int, scores))
average = mean(scores)
namelist = name
averagelist=average
print(namelist, averagelist)
yield namelist, averagelist
print(calculate_averages('namelist', 'averagelist'))
I put print n the code to see if where the problem is: when I use return it gives me :
mahtaab 15.5
Reza 14
Mahyar 15.5
Shamim 17.166666666666668
Milad 13.5
('Milad', 13.5)
when I use yield it returns:
<generator object calculate_averages at 0x0000019FB6474BA0>
what is the problem?