Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 02-basic-python/02-basic-python-in-class.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -859,9 +859,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -873,7 +873,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.5"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down
190 changes: 162 additions & 28 deletions 02-basic-python/02-basic-python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"## Jupyter Notebook Basics\n",
"\n",
Expand Down Expand Up @@ -234,14 +236,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"pycharm": {
"is_executing": false
},
"scrolled": true
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World!\n"
]
},
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print (\"Hello World!\")\n",
"a = 3\n",
Expand All @@ -265,7 +285,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"pycharm": {
"is_executing": false
Expand All @@ -274,7 +294,7 @@
"outputs": [],
"source": [
"age = 2\n",
"gender = \"woman\"\n",
"gender = \"female\"\n",
"name = \"Datascience Cat\"\n",
"smart = True"
]
Expand All @@ -292,9 +312,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Datascience Cat, age: 2, female, is smart: True\n"
]
}
],
"source": [
"print(name + \", age: \" + str(age) + \", \" + \n",
" gender + \", is smart: \" + str(smart))"
Expand All @@ -311,9 +339,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Datascience Cat \n",
" age: 2 \n",
" female \n",
" is smart: True\n"
]
}
],
"source": [
"print(name, \"\\n\",\n",
" \"age:\", age, \"\\n\",\n",
Expand All @@ -339,6 +378,28 @@
"3. Modify the above print statement to add your UID and email to the print-out."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"uID: u146792 \n",
" email: hadleyblackwell05@gmail.com\n"
]
}
],
"source": [
"uID = \"u146792\"\n",
"email = \"hadleyblackwell05@gmail.com\"\n",
"\n",
"print(\"uID: \", uID, \"\\n\",\n",
" \"email: \", email)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -530,9 +591,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Within function: only readable in here\n"
]
}
],
"source": [
"def scope_test():\n",
" function_scope = \"only readable in here\"\n",
Expand All @@ -554,11 +623,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"print(\"Outside function: \" + function_scope)"
"# print(\"Outside function: \" + function_scope)\n",
"# supressed output since incorrect"
]
},
{
Expand All @@ -574,9 +644,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dr. Science Cat\n"
]
}
],
"source": [
"name = \"Science Cat\"\n",
"\n",
Expand All @@ -595,9 +673,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dr. Science Cat\n"
]
}
],
"source": [
"# note that we're re-using the parameter name defined in the previous cell.\n",
"def print_name_with_dr(name):\n",
Expand All @@ -615,9 +701,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Within function: defined in the function, global scope\n",
"Outside function: defined in the function, global scope\n"
]
}
],
"source": [
"def scope_test():\n",
" # Think long and hard before you do this - generally you shouldn't. I have never.\n",
Expand Down Expand Up @@ -646,6 +741,45 @@
"3. When you try each function, what is the result? What is the value of the `x` outside the function?"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the result of add7 is: 9\n",
"the result of the second function is: 9\n",
"the result of the third function is: 10\n"
]
}
],
"source": [
"x = 2\n",
"\n",
"def add7(x):\n",
" result = x + 7\n",
" print(\"the result of add7 is: \", result)\n",
"\n",
"add7(x)\n",
"\n",
"def second_add7():\n",
" x = 2\n",
" result2 = x + 7\n",
" print(\"the result of the second function is: \", result2)\n",
"\n",
"second_add7()\n",
"\n",
"def third_add7(x):\n",
" x=3\n",
" result3 = x + 7\n",
" print(\"the result of the third function is: \", result3)\n",
"\n",
"third_add7(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -658,9 +792,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -672,7 +806,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.5"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down
29 changes: 23 additions & 6 deletions 02-basic-python/02-bonus-exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"7.2\n",
"<class 'float'>\n"
]
}
],
"source": [
"# your code"
"# your code\n",
"a = 3\n",
"b = 4.2\n",
"#type(a)\n",
"#type(b)\n",
"\n",
"c = a + b\n",
"print(c)\n",
"print(type(c))"
]
},
{
Expand Down Expand Up @@ -94,9 +111,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -108,7 +125,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.5"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down
Loading