You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"# Session 1 Python Tutorial/ Parsing of a File Tutorial\n",
8
8
"\n",
9
9
"*Written By: **Nicholas Archibong\n",
10
10
"\n",
11
-
"In this Tutorial, you are taken through how to open a csv file, going through the file and checking for a specific entry, changing that entry, adding in a new coloumn, and finally writing the changed file into a new file for other purposes. \n"
11
+
"In this Tutorial, you are taken through how to open a csv file, going through the file and checking for a specific entry, changing that entry, adding in a new coloumn, writing the changed file into a new file for other purposes, as well as going over some basics in python. \n"
12
12
]
13
13
},
14
14
{
@@ -17,29 +17,23 @@
17
17
"source": [
18
18
"#### Reading in of file\n",
19
19
"\n",
20
-
"In this section, the csv module is imported into our script to allow access to some of their useful methods. Such as reading in a file and writing to a file. "
20
+
"In this section, the csv module is imported into our script to allow access to some of their useful methods. Such as reading in a file and writing to a file. \n",
21
+
"\n",
22
+
"*** You will have to change the readFile and writeFile to the location of the github repository that you cloned onto your desktop"
"with open(readFile, 'r') as rf: # open csv file\n",
45
39
" data = csv.reader(rf) # read in csv file\n",
@@ -48,6 +42,117 @@
48
42
"print(playerList)"
49
43
]
50
44
},
45
+
{
46
+
"cell_type": "markdown",
47
+
"metadata": {},
48
+
"source": [
49
+
"#### Loop Practice\n",
50
+
"\n",
51
+
"There are two type of loops in python, the while loop and the for loop. Both have similar functionality, however, they have their key differences. A while loop is used for iterations where the end is not known, while the for loop could be used for iterations where the end is known, or you have a specific number of iterations to complete. "
52
+
]
53
+
},
54
+
{
55
+
"cell_type": "markdown",
56
+
"metadata": {},
57
+
"source": [
58
+
"##### Counting of numbers from 1 to 10\n",
59
+
"\n",
60
+
"This example, you are to complete the code to have both the while loop and the for loop count from 1 to 10. "
61
+
]
62
+
},
63
+
{
64
+
"cell_type": "code",
65
+
"execution_count": null,
66
+
"metadata": {},
67
+
"outputs": [],
68
+
"source": [
69
+
"for num in range(,):\n",
70
+
" print(num)"
71
+
]
72
+
},
73
+
{
74
+
"cell_type": "code",
75
+
"execution_count": null,
76
+
"metadata": {},
77
+
"outputs": [],
78
+
"source": [
79
+
"countNum = \n",
80
+
"while countNum <= :\n",
81
+
" print(countNum)\n",
82
+
" countNum += "
83
+
]
84
+
},
85
+
{
86
+
"cell_type": "markdown",
87
+
"metadata": {},
88
+
"source": [
89
+
"#### More practice with loops\n",
90
+
"\n",
91
+
"In the next example, there is a list of strings. You are tasked with completing the code that is missing in order to find the string name 'Avery'. \n",
92
+
"\n",
93
+
"Counter Concept: A counter is a variable that typically increments when you go through an iteration of a loop. It's useful in the sense that you could use a counter to access list indices. "
"The input funciton is used to gather information from the user. You could type cast it to change the type from string to any of the other data types. "
137
+
]
138
+
},
139
+
{
140
+
"cell_type": "code",
141
+
"execution_count": null,
142
+
"metadata": {},
143
+
"outputs": [],
144
+
"source": [
145
+
"userInput = 'c'\n",
146
+
"whileCounter = 1\n",
147
+
"\n",
148
+
"while userInput != 'q':\n",
149
+
" userInput = input('To quit please enter \\'q\\': ').lower()\n",
150
+
" whileCounter += 1\n",
151
+
"\n",
152
+
"print('Program Terminated...')\n",
153
+
"print('Number of iterations is...%',whileCounter)"
154
+
]
155
+
},
51
156
{
52
157
"cell_type": "markdown",
53
158
"metadata": {},
@@ -56,24 +161,18 @@
56
161
"\n",
57
162
"In this section of code, you, the user, are looking for a \"specific value\" in the file. This specific value could be anything you want it, however, in this file, there are missing values \"''\" which you would like to replace with a 'NULL' instead to signify that that particular value was missing. \n",
58
163
"\n",
59
-
"A nested for loop is used to access the indcies of the nest list. This allows us to hit every index and check if there if it is missing a value or not. Two counters are used to allow the for loops to traverse the list correctly. "
164
+
"A nested for loop is used to access the indcies of the nest list. This allows us to hit every index and check if there if it is missing a value or not. Two counters are used to allow the for loops to traverse the list correctly. \n",
0 commit comments