Page 138 - Programming With Python 3
P. 138
An Introduction to STEM Programming with Python — 2019-09-03a Page 125
Chapter 10 — Files
11| ['09/18/2018',31,32,43,63,68,17,2],
12| ['09/21/2018',1,2,11,52,64,9,4],
Free
13| ['09/25/2018',8,16,32,48,61,12,2],
14| ['09/28/2018',39,45,52,56,59,15,3],
15| ['10/02/2018',2,22,29,31,34,1,3],
16| ['10/05/2018',27,28,32,41,69,12,2],
17| ['10/09/2018',20,22,39,54,60,18,3],
18| ['10/12/2018',4,24,46,61,70,7,3],
eBook
19| ['10/16/2018',3,45,49,61,69,9,5],
20| ['10/19/2018',15,23,53,65,70,7,2],
21| ['10/23/2018',5,28,62,65,70,5,3],
22| ['10/26/2018',1,28,61,62,63,5,4],
23| ['10/30/2018',20,31,39,46,49,23,2],
24| ['11/02/2018',3,23,28,46,62,16,2],
Edition
25| ['11/06/2018',28,34,37,56,69,12,2],
26| ['11/09/2018',8,14,27,57,67,5,4],
27| ['11/13/2018',34,46,57,65,69,11,3],
28| ['11/16/2018',33,36,63,68,69,16,3],
29| ['11/20/2018',10,16,31,42,66,10,3]
30| ]
Please support this work at
31| import csv
32| with open("mega.csv","w", newline='') as f:
33| fw = csv.writer(f)
34| for m in mega:
http://syw2l.org
35| fw.writerow(m)
36| print("done")
The file mega.csv should contain:
08/31/2018,7,18,29,32,45,17,3\n Free
09/04/2018,2,7,25,35,44,3,3\n
09/07/2018,8,10,41,54,68,10,2\n
09/11/2018,15,30,51,62,67,19,2\n
...
11/20/2018,10,16,31,42,66,10,3\n eBook
Now let's write a program to open the mega.csv file and count the number of times that a white ball has
been drawn. Looking at the data the 5 white balls are at index 1-5. Remember that the csv.reader
returns a list of strings, and we need to convert them to integer ball numbers.
1| import csv
2| try: Edition
3| ball = int(input("enter ball number to count>> "))
Copyright 2019 — James M. Reneau Ph.D. — http://www.syw2l.org — This work is licensed
under a Creative Commons Attribution-ShareAlike 4.0 International License.

