Skip to content

Commit e206300

Browse files
committed
Detailed review of part 3 greeting section.
1 parent 3d9ed15 commit e206300

File tree

1 file changed

+131
-18
lines changed

1 file changed

+131
-18
lines changed

part-3.ipynb

Lines changed: 131 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"name": "python2"
1111
},
1212
"name": "",
13-
"signature": "sha256:98933314083fad8f511ddedbb2e2864dc55638392d8ce23f6cb46b78f049a2a3"
13+
"signature": "sha256:21fa40ef7368043bdaf558035d71a9c7d07f9c147ef8083eadd7fe8a891b7ca2"
1414
},
1515
"nbformat": 3,
1616
"nbformat_minor": 0,
@@ -67,7 +67,9 @@
6767
"cell_type": "markdown",
6868
"metadata": {},
6969
"source": [
70-
"Say we have a simple program that prints a happy birthday greeting:"
70+
"Say we have a simple program that prints a happy birthday greeting for Carol.\n",
71+
"\n",
72+
"It's not Carol's birthday, but let's run this program anyway, just to confuse her in good fun ;)"
7173
]
7274
},
7375
{
@@ -78,7 +80,16 @@
7880
],
7981
"language": "python",
8082
"metadata": {},
81-
"outputs": []
83+
"outputs": [
84+
{
85+
"output_type": "stream",
86+
"stream": "stdout",
87+
"text": [
88+
"Happy Birthday, dear Carol!\n"
89+
]
90+
}
91+
],
92+
"prompt_number": 1
8293
},
8394
{
8495
"cell_type": "markdown",
@@ -96,7 +107,8 @@
96107
],
97108
"language": "python",
98109
"metadata": {},
99-
"outputs": []
110+
"outputs": [],
111+
"prompt_number": 3
100112
},
101113
{
102114
"cell_type": "heading",
@@ -150,7 +162,9 @@
150162
"cell_type": "markdown",
151163
"metadata": {},
152164
"source": [
153-
"Don't forget those parenthesis. Without the parenthesis Python wouldn't know we were trying to call our function, and will print out a statement "
165+
"Don't forget those parentheses. \n",
166+
"\n",
167+
"Without the parentheses, Python wouldn't know that we were trying to call our function, and will print out the value of the thing called `happy_birthday_carol`."
154168
]
155169
},
156170
{
@@ -161,13 +175,38 @@
161175
],
162176
"language": "python",
163177
"metadata": {},
164-
"outputs": []
178+
"outputs": [
179+
{
180+
"metadata": {},
181+
"output_type": "pyout",
182+
"prompt_number": 4,
183+
"text": [
184+
"<function __main__.happy_birthday_carol>"
185+
]
186+
}
187+
],
188+
"prompt_number": 4
189+
},
190+
{
191+
"cell_type": "markdown",
192+
"metadata": {},
193+
"source": [
194+
"Here, the Python interpreter is basically saying, \"The value of happy_birthday_carol is a function.\""
195+
]
196+
},
197+
{
198+
"cell_type": "heading",
199+
"level": 3,
200+
"metadata": {},
201+
"source": [
202+
"Let's define and call another function"
203+
]
165204
},
166205
{
167206
"cell_type": "markdown",
168207
"metadata": {},
169208
"source": [
170-
"We can create a slew of functions named in a similar fashion:"
209+
"That function printed a nice greeting for Carol. But Rise's now feeling left out. Let's define a function for her too."
171210
]
172211
},
173212
{
@@ -179,7 +218,15 @@
179218
],
180219
"language": "python",
181220
"metadata": {},
182-
"outputs": []
221+
"outputs": [],
222+
"prompt_number": 5
223+
},
224+
{
225+
"cell_type": "markdown",
226+
"metadata": {},
227+
"source": [
228+
"Now, let's call the function:"
229+
]
183230
},
184231
{
185232
"cell_type": "code",
@@ -189,7 +236,24 @@
189236
],
190237
"language": "python",
191238
"metadata": {},
192-
"outputs": []
239+
"outputs": [
240+
{
241+
"output_type": "stream",
242+
"stream": "stdout",
243+
"text": [
244+
"Happy Birthday, dear Rise!\n"
245+
]
246+
}
247+
],
248+
"prompt_number": 6
249+
},
250+
{
251+
"cell_type": "heading",
252+
"level": 3,
253+
"metadata": {},
254+
"source": [
255+
"Refactor time!"
256+
]
193257
},
194258
{
195259
"cell_type": "markdown",
@@ -201,7 +265,7 @@
201265
"\n",
202266
"Python allows us to do just that with function parameters. We can add a parameter by typing a variable name in between the parethesis after our function name. We can then use the parameter variable in our function.\n",
203267
"\n",
204-
"We'll create a new function called 'happy_birthday', and add a parameter, 'name'."
268+
"We'll create a new function called `happy_birthday`, and add a parameter, `name`."
205269
]
206270
},
207271
{
@@ -213,13 +277,24 @@
213277
],
214278
"language": "python",
215279
"metadata": {},
216-
"outputs": []
280+
"outputs": [],
281+
"prompt_number": 18
282+
},
283+
{
284+
"cell_type": "markdown",
285+
"metadata": {},
286+
"source": [
287+
"Here, we are concatenating 3 strings:\n",
288+
"* \"Happy Birthday, dear \"\n",
289+
"* whatever the value of `name` is (Note: for the purposes of this example, let's assume that we're always getting a string)\n",
290+
"* \"!\""
291+
]
217292
},
218293
{
219294
"cell_type": "markdown",
220295
"metadata": {},
221296
"source": [
222-
"To execute or run our new function, we simply call it by its name, 'happy_birthday' and pass a value in between the parenthesis, such as the string, 'Trey'."
297+
"To execute or run our new function, we simply call it by its name, `happy_birthday`, and pass a value in between the parenthesis, such as the string `Trey`."
223298
]
224299
},
225300
{
@@ -230,13 +305,30 @@
230305
],
231306
"language": "python",
232307
"metadata": {},
233-
"outputs": []
308+
"outputs": [
309+
{
310+
"output_type": "stream",
311+
"stream": "stdout",
312+
"text": [
313+
"Happy Birthday, dear Trey!\n"
314+
]
315+
}
316+
],
317+
"prompt_number": 19
318+
},
319+
{
320+
"cell_type": "heading",
321+
"level": 3,
322+
"metadata": {},
323+
"source": [
324+
"Calling it over and over in a loop"
325+
]
234326
},
235327
{
236328
"cell_type": "markdown",
237329
"metadata": {},
238330
"source": [
239-
"Let's get a little bolder and make a list of names that we can loop over and then pass each one into our 'happy_birthday' function. What we get is the same results as the other earlier lines of code!"
331+
"Let's get a little bolder and make a list of names that we can loop over and then pass each one into our `happy_birthday` function. What we get is the same results as the other earlier lines of code!"
240332
]
241333
},
242334
{
@@ -247,7 +339,8 @@
247339
],
248340
"language": "python",
249341
"metadata": {},
250-
"outputs": []
342+
"outputs": [],
343+
"prompt_number": 23
251344
},
252345
{
253346
"cell_type": "code",
@@ -258,17 +351,37 @@
258351
],
259352
"language": "python",
260353
"metadata": {},
261-
"outputs": []
354+
"outputs": [
355+
{
356+
"output_type": "stream",
357+
"stream": "stdout",
358+
"text": [
359+
"Happy Birthday, dear Carol!\n",
360+
"Happy Birthday, dear Rise!\n",
361+
"Happy Birthday, dear Trey!\n",
362+
"Happy Birthday, dear Alain!\n"
363+
]
364+
}
365+
],
366+
"prompt_number": 24
367+
},
368+
{
369+
"cell_type": "heading",
370+
"level": 2,
371+
"metadata": {},
372+
"source": [
373+
"Example: Cupcake Calculation Function"
374+
]
262375
},
263376
{
264377
"cell_type": "markdown",
265378
"metadata": {},
266379
"source": [
267380
"Now, let's see what we need to do to make a function return a value to where the function was initially called.\n",
268381
"\n",
269-
"So let's create a new function, 'get_cupcake_count'.\n",
382+
"So let's create a new function, `get_cupcake_count`.\n",
270383
"\n",
271-
"We'll multiple the number of guests by two and return the result because each guest wants to eat two cupcakes."
384+
"We'll multiply the number of guests by two and return the result because each guest wants to eat two cupcakes."
272385
]
273386
},
274387
{

0 commit comments

Comments
 (0)