Answer to Question #329328 in Python for xxx

Question #329328

1. Given the scores of students for Mathematics, English and Science, calculate the average score of each student and store it in a list.

2. Write the names, scores of each subject and average scores into a text file or csv file.


Code:

names = ['Zendaya', 'Yaacob', 'Xander', 'Willy',

     'Vega', 'Umar', 'Takata', 'Sheena', 'Rhina', 'Queen']


math = [67, 73, 71, 11, 51, 46, 29, 51, 66, 25]

english = [87, 48, 93, 41, 69, 43, 0, 17, 78, 74]

science = [73, 71, 17, 81, 8, 33, 39, 33, 17, 93]


1
Expert's answer
2022-04-16T06:48:04-0400
import csv

names = ['Zendaya', 'Yaacob', 'Xander', 'Willy',
  'Vega', 'Umar', 'Takata', 'Sheena', 'Rhina', 'Queen']

math = [67, 73, 71, 11, 51, 46, 29, 51, 66, 25]
english = [87, 48, 93, 41, 69, 43, 0, 17, 78, 74]
science = [73, 71, 17, 81, 8, 33, 39, 33, 17, 93]

avg = [sum(grades) / len(grades) for grades in zip(math, english, science)]

fields = ['Name', 'Math', 'English', 'Science', 'Average']
filename = 'grades_records.csv'

with open(filename, 'w') as fout:
  writer = csv.writer(fout)
  writer.writerow(fields)
  writer.writerows(zip(names, math, english, science, avg))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS