This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 7: More file handling

Exercise

face Josiah Wang

Just a quick final exercise on writing CSV files and we are done!

You will build on your code earlier for reading grades.csv. After reading the data from that file, your task is to output a new CSV file called "final.csv". We are only interested in the final grade and marks of the students, and we prefer to have the student’s first name in the first column, and the last name in the second column.

You output "final.csv" should look like below:

First name,Last name,Final,Grade
Aloysius,Alfalfa,49.0,D-
University,Alfred,48.0,D+
Gramma,Gerty,44.0,C
Electric,Android,47.0,B-
Fred,Bumpkin,45.0,A-
Betty,Rubble,46.0,C-
Cecil,Noshow,43.0,F
Bif,Buff,50.0,B+
Andrew,Airpump,83.0,A
Jim,Backus,97.0,A+
Art,Carnivore,40.0,D+
Jim,Dandy,45.0,C+
Ima,Elephant,77.0,B-
Benny,Franklin,90.0,B-
Boy,George,4.0,B
Harvey,Heffalump,40.0,C

It’s up to you whether you want to use csv.writer() or csv.DictWriter (or both if you wish!)