Sep-29-2019, 12:48 PM
(This post was last modified: Sep-29-2019, 12:55 PM by LeegeeRicky.)
(Sep-29-2019, 11:59 AM)ichabod801 Wrote: You need to check each value before you sum it, and if it's empty, treat it as zero. Something like:auto_score = int(row['Auto Score']) if row['Auto Score'].strip() else 0
I do a bit changed on my code as you said, but I got error when I try to sum then
import csv with open("exam_for_2019.csv") as csvfile: reader = csv.DictReader(csvfile) for row in reader: auto_score = float(row['Auto Score']) if row['Auto Score'].strip() else 0 Manual_Score = float(row['Manual Score']) if row['Manual Score'].strip() else 0 sum_row = float(auto_score) + float(Manual_Score) sums = sum(sum_row) print(sums)And I get TypeError: 'float' object is not iterable
(Sep-29-2019, 11:59 AM)ichabod801 Wrote: You need to check each value before you sum it, and if it's empty, treat it as zero. Something like:
auto_score = int(row['Auto Score']) if row['Auto Score'].strip() else 0
And also is possible assign the total number with each user name?
Like
Username Total
1234, 4.5
345, 4
133, 4.5