How do I get it to print out the total grade?

Question:

I added in the ‘int’ like it was suggested as shown below

  import csv
  with open("./student_grades.csv", newline='') as csvfile:
  data = csv.reader(csvfile)
  print("Banner Total Grade")
   print("---------------------------------")
  for row in data:
  grade = int(row['Math']) + int(row['Physics']) + int(row['Chemistry']) + int(row['Biology'])
  print(row['banner'], grade)

After I add in int now I’m getting a value error

    ValueError                                
    Traceback (most recent call last)
    Input In [135], in <cell line: 7>()
      5   print("Banner Total Grade")
      6   print("---------------------------------")
    ----> 7 for row in data:
      8     grade = int(row['Math']) + int(row['Physics']) + int(row['Chemistry']) + int(row['Biology'])
      9 print(row['banner'], grade)

    ValueError: I/O operation on closed file.
Asked By: Ashley

||

Answers:

Just cast each of the grades into integer. For example,

   int(row['maths']) 

and if your grades are in float then you can use float as well.

Answered By: Abhishek Mishra
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.