Skip to content

Commit 50fcc3f

Browse files
finish up loops and logic, add more about math to intro
1 parent c02e590 commit 50fcc3f

File tree

2 files changed

+446
-3
lines changed

2 files changed

+446
-3
lines changed

Intro_To_Python.ipynb

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@
155155
"execution_count": null,
156156
"source": [
157157
"his_name = \"John\"\n",
158-
"print(\"His name is \" + his_name)"
158+
"print(\"His name is \" + his_name)\n",
159+
"my_name # complete the variable declaration here!\n",
160+
"print() # now print out your name"
159161
],
160162
"id": "386473072062d87b"
161163
},
@@ -171,15 +173,20 @@
171173
{
172174
"metadata": {},
173175
"cell_type": "markdown",
174-
"source": "",
176+
"source": "Just as a note, all of these exercises are completely optional, but they are here for _your_ sake. I'll never know if you skip one, but you're only harming yourself.",
175177
"id": "9e23604b2828ea85"
176178
},
177179
{
178180
"metadata": {},
179181
"cell_type": "code",
180182
"outputs": [],
181183
"execution_count": null,
182-
"source": "## Your turn :3",
184+
"source": [
185+
"## Your turn :3\n",
186+
"# Declare the variables here\n",
187+
"\n",
188+
"# Print theme all out in a single print statement"
189+
],
183190
"id": "7a37bd8062631e39"
184191
},
185192
{
@@ -289,6 +296,82 @@
289296
"print(\"Comment out this line!\")"
290297
],
291298
"id": "b18a664c7e3bdf06"
299+
},
300+
{
301+
"metadata": {},
302+
"cell_type": "code",
303+
"outputs": [],
304+
"execution_count": null,
305+
"source": "",
306+
"id": "f7c25dd39f9be227"
307+
},
308+
{
309+
"metadata": {},
310+
"cell_type": "markdown",
311+
"source": [
312+
"## Math in Python\n",
313+
"Python can be used as a calculator, and it supports all the basic arithmetic operations like addition, subtraction, multiplication, and division. Here are some examples:"
314+
],
315+
"id": "7a7153dec817dae3"
316+
},
317+
{
318+
"metadata": {},
319+
"cell_type": "code",
320+
"outputs": [],
321+
"execution_count": null,
322+
"source": [
323+
"print(5 + 3) # Addition\n",
324+
"print(5 - 3) # Subtraction\n",
325+
"print(5 * 3) # Multiplication\n",
326+
"print(5 / 3) # Division\n",
327+
"print(5 // 3) # Floor Division\n",
328+
"print(5 % 3) # Modulus\n",
329+
"print(5 ** 3) # Exponentiation\n",
330+
"print(5 + 3 * 2) # Order of operations"
331+
],
332+
"id": "a997cca30aa3c69e"
333+
},
334+
{
335+
"metadata": {},
336+
"cell_type": "markdown",
337+
"source": [
338+
"Python also has shorthand operators that allow you to perform an operation and assign the result to a variable in a single step. For example, instead of writing `x = x + 5`, you can write `x += 5`. This shorthand also works with strings, where applicable.\n",
339+
"Here are some examples of shorthand operators:"
340+
],
341+
"id": "2ec0b39771d28739"
342+
},
343+
{
344+
"metadata": {},
345+
"cell_type": "code",
346+
"outputs": [],
347+
"execution_count": null,
348+
"source": [
349+
"x = 6\n",
350+
"x += 3 # Equivalent to x = x + 3\n",
351+
"print(x)\n",
352+
"y = \"Hello\"\n",
353+
"y += \" World!\" # Equivalent to y = y + \" World!\"\n",
354+
"print(y)\n",
355+
"x *= 2 # Equivalent to x = x * 2\n",
356+
"print(x)"
357+
],
358+
"id": "231580ff6f38832b"
359+
},
360+
{
361+
"metadata": {},
362+
"cell_type": "markdown",
363+
"source": [
364+
"## Practice - Ask a user for their info, and format it\n",
365+
"\n",
366+
"Let's put all of this together and create a simple \"Registration\" program that asks the user for their name, age, and password, and then prints out a formatted sentence with that information. You can use the `input()` function to get input from the user, and then use string formatting to create the final output. We have little under our toolbelt yet, so let's keep it simple. "
367+
],
368+
"id": "3230f4039fd83fb7"
369+
},
370+
{
371+
"metadata": {},
372+
"cell_type": "markdown",
373+
"source": "",
374+
"id": "4f9f1e949d0978a1"
292375
}
293376
],
294377
"metadata": {

0 commit comments

Comments
 (0)