Lesson 4 of 7
Aggregate CSV data
The aggregation pattern: initialise an accumulator, walk the rows, convert strings to numbers, accumulate.
int() for quantities, float() for prices — and round(x, 2) whenever money is involved.
for row in rows:
revenue = revenue + int(row["qty"]) * float(row["price"])🎯 Exercise
From DATA (same columns as before), compute revenue: the sum of qty × price for each row, rounded to 2 decimals. Print revenue.
PRO lesson
This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.
Discover PRO →