Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A CSV text has the header item,price,quantity and the rows pen,10,3, book,80,1 and bag,450,2. Use csv.DictReader to find the total cost, the sum of price times quantity of every row.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Read the rows as dictionaries, convert the texts into numbers, and add up price times quantity.
Check. pen: 10 times 3 = 30. book: 80 times 1 = 80. bag: 450 times 2 = 900. The total is 30 + 80 + 900 = 1010.
Answer: 1010.
Log in to join the discussion.
Loading…