Issue
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.
Solution
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
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.