From 899dbf03e4a9a90721fd57f44952ed4770465eed Mon Sep 17 00:00:00 2001 From: Lalla Sankara Date: Tue, 19 Mar 2024 21:35:38 -0700 Subject: [PATCH 1/6] class one answers answers to class one, data type lessons --- .idea/.gitignore | 3 +++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/intro-python.iml | 12 +++++++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ class_one/01_data_types.py | 20 ++++++++++++++++++- 7 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/intro-python.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/intro-python.iml b/.idea/intro-python.iml new file mode 100644 index 0000000..8b8c395 --- /dev/null +++ b/.idea/intro-python.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..61a3499 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f1cb4ee --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/class_one/01_data_types.py b/class_one/01_data_types.py index c7d819d..c3140eb 100644 --- a/class_one/01_data_types.py +++ b/class_one/01_data_types.py @@ -1,5 +1,6 @@ ## Learn More Python with Automate the Boring Stuff: ## https://automatetheboringstuff.com/chapter1/ +import numbers # Your First Program # @@ -18,16 +19,19 @@ # What is type(a)? +# integer # What is type(b)? +# float # What is c? +# float # What is d? - +# float # EXERCISES @@ -36,18 +40,32 @@ # What is type(e)? +# list # What is len(e)? +# 2 # What is type(f)? +#list # What are the contents of f? +# contents are [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ] # What is 'list' called? # hint: google it +# A list is simply called list + +# A list is used to store collections of items, where each item in the list can be of any data type, and the items are +# ordered and mutable. # What is 'range' called? What happens when you run 'help(range)'? +# In python range is a built in fuction. It's used to generate a sequence of numbers. +# When you run help(range) in Python, it displays information about the range function, including its usage, +# parameters, and return value. + +help(range) + From 9dfe44ef1d0d1bc94347db6876e2fd45bc7033a9 Mon Sep 17 00:00:00 2001 From: Lalla Sankara Date: Mon, 25 Mar 2024 20:18:54 -0700 Subject: [PATCH 2/6] Update 01_data_types.py answers to class one --- class_one/01_data_types.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/class_one/01_data_types.py b/class_one/01_data_types.py index c3140eb..17e3842 100644 --- a/class_one/01_data_types.py +++ b/class_one/01_data_types.py @@ -4,7 +4,7 @@ # Your First Program # -# print('hello world') + print('hello world') # # # Comments in python use a '#' # # Remove the # in front of code to run it @@ -40,7 +40,7 @@ # What is type(e)? -# list +# Its the data type list # What is len(e)? @@ -48,24 +48,24 @@ # What is type(f)? -#list +#Its the data type list # What are the contents of f? -# contents are [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ] +# The contents are [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ] # What is 'list' called? # hint: google it -# A list is simply called list - -# A list is used to store collections of items, where each item in the list can be of any data type, and the items are +# A list is simply called list in python. A list is used to store collections of items, where each item in the list can be of any data type, and the items are # ordered and mutable. # What is 'range' called? What happens when you run 'help(range)'? -# In python range is a built in fuction. It's used to generate a sequence of numbers. +# In python range is a built in function. It's used to generate a sequence of numbers. # When you run help(range) in Python, it displays information about the range function, including its usage, # parameters, and return value. -help(range) +## Results from running help (range) +f = list(range(0, 10)) +help (range) From dc5c3f10b2a5e1bebc61340f1013378760c75a55 Mon Sep 17 00:00:00 2001 From: Lalla Sankara Date: Mon, 25 Mar 2024 20:20:32 -0700 Subject: [PATCH 3/6] Update 01_data_types.py --- class_one/01_data_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class_one/01_data_types.py b/class_one/01_data_types.py index 17e3842..28c5203 100644 --- a/class_one/01_data_types.py +++ b/class_one/01_data_types.py @@ -4,7 +4,7 @@ # Your First Program # - print('hello world') +print('hello world') # # # Comments in python use a '#' # # Remove the # in front of code to run it From 6d026e1e76f381047705f5d060029aaa3eaa5fff Mon Sep 17 00:00:00 2001 From: Lalla Sankara Date: Mon, 25 Mar 2024 20:43:51 -0700 Subject: [PATCH 4/6] jupyter notebook switch --- .idea/intro-python.iml | 6 +- .idea/misc.xml | 2 +- class_one/01_data_types.py | 71 ------- class_one/01_data_types.py.ipynb | 309 +++++++++++++++++++++++++++++++ class_one/untitled | 0 5 files changed, 314 insertions(+), 74 deletions(-) delete mode 100644 class_one/01_data_types.py create mode 100644 class_one/01_data_types.py.ipynb create mode 100644 class_one/untitled diff --git a/.idea/intro-python.iml b/.idea/intro-python.iml index 8b8c395..b7de71d 100644 --- a/.idea/intro-python.iml +++ b/.idea/intro-python.iml @@ -1,8 +1,10 @@ - - + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 61a3499..8f71b40 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/class_one/01_data_types.py b/class_one/01_data_types.py deleted file mode 100644 index 28c5203..0000000 --- a/class_one/01_data_types.py +++ /dev/null @@ -1,71 +0,0 @@ -## Learn More Python with Automate the Boring Stuff: -## https://automatetheboringstuff.com/chapter1/ -import numbers - -# Your First Program -# -print('hello world') -# -# # Comments in python use a '#' -# # Remove the # in front of code to run it - -## WARM UP QUIZ - -# PART I -a = 5 -b = 5.0 -c = a / 2 -d = b / 2 - -# What is type(a)? - -# integer - -# What is type(b)? - -# float - -# What is c? - -# float - -# What is d? - -# float - -# EXERCISES - -e = [a, b] -f = list(range(0, 10)) - -# What is type(e)? - -# Its the data type list - -# What is len(e)? - -# 2 - -# What is type(f)? - -#Its the data type list - -# What are the contents of f? - -# The contents are [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ] - -# What is 'list' called? # hint: google it - -# A list is simply called list in python. A list is used to store collections of items, where each item in the list can be of any data type, and the items are -# ordered and mutable. - -# What is 'range' called? What happens when you run 'help(range)'? - -# In python range is a built in function. It's used to generate a sequence of numbers. -# When you run help(range) in Python, it displays information about the range function, including its usage, -# parameters, and return value. - -## Results from running help (range) - -f = list(range(0, 10)) -help (range) diff --git a/class_one/01_data_types.py.ipynb b/class_one/01_data_types.py.ipynb new file mode 100644 index 0000000..d1184ed --- /dev/null +++ b/class_one/01_data_types.py.ipynb @@ -0,0 +1,309 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "da3d1fe2", + "metadata": {}, + "outputs": [], + "source": [ + "## Learn More Python with Automate the Boring Stuff:\n", + "## https://automatetheboringstuff.com/chapter1/\n", + "import numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "aca0980e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello world\n" + ] + } + ], + "source": [ + "# Your First Program\n", + "print('hello world')\n", + "# # Comments in python use a '#'\n", + "# # Remove the # in front of code to run it" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "67241b0e", + "metadata": {}, + "outputs": [], + "source": [ + "## WARM UP QUIZ\n", + "# PART I\n", + "a = 5\n", + "b = 5.0\n", + "c = a / 2\n", + "d = b / 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d0e7eafe", + "metadata": {}, + "outputs": [], + "source": [ + "# What is type(a)?\n", + "\n", + "# Its an integer" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d731210b", + "metadata": {}, + "outputs": [], + "source": [ + "# What is type(b)?\n", + "\n", + "# Its a float\n", + "\n", + "# What is c?\n", + "\n", + "# ITs a float\n", + "\n", + "# What is d?\n", + "\n", + "# Its a float" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "246cb717", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# EXERCISES\n", + "e = [a, b]\n", + "f = list(range(0, 10))\n", + "(len(e))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f5967341", + "metadata": {}, + "outputs": [], + "source": [ + "# What is type(e)?\n", + "\n", + "# It's the data type list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f61a79e4", + "metadata": {}, + "outputs": [], + "source": [ + "# What is len(e)?\n", + "\n", + "# len (e) give the length of the list which is 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "54cfa5e5", + "metadata": {}, + "outputs": [], + "source": [ + "# What is type(f)?\n", + "\n", + "# Its the data type list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "46afebcc", + "metadata": {}, + "outputs": [], + "source": [ + "# What are the contents of f?\n", + "\n", + "# The contents are [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "25150070", + "metadata": {}, + "outputs": [], + "source": [ + "# What is 'list' called? # hint: google it\n", + "\n", + "# A list is simply called list in python. A list is used to store collections of items, \n", + "# where each item in the list can be of any data type, and the items are\n", + "# ordered and mutable." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de3294c3", + "metadata": {}, + "outputs": [], + "source": [ + "# What is 'range' called? What happens when you run 'help(range)'?\n", + "\n", + "# In python range is a built in function. It's used to generate a sequence of numbers.\n", + "# When you run help(range) in Python, it displays information about the range function, including its usage,\n", + "# parameters, and return value" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "006dbc75", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on class range in module builtins:\n", + "\n", + "class range(object)\n", + " | range(stop) -> range object\n", + " | range(start, stop[, step]) -> range object\n", + " | \n", + " | Return an object that produces a sequence of integers from start (inclusive)\n", + " | to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1.\n", + " | start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3.\n", + " | These are exactly the valid indices for a list of 4 elements.\n", + " | When step is given, it specifies the increment (or decrement).\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | __bool__(self, /)\n", + " | True if self else False\n", + " | \n", + " | __contains__(self, key, /)\n", + " | Return key in self.\n", + " | \n", + " | __eq__(self, value, /)\n", + " | Return self==value.\n", + " | \n", + " | __ge__(self, value, /)\n", + " | Return self>=value.\n", + " | \n", + " | __getattribute__(self, name, /)\n", + " | Return getattr(self, name).\n", + " | \n", + " | __getitem__(self, key, /)\n", + " | Return self[key].\n", + " | \n", + " | __gt__(self, value, /)\n", + " | Return self>value.\n", + " | \n", + " | __hash__(self, /)\n", + " | Return hash(self).\n", + " | \n", + " | __iter__(self, /)\n", + " | Implement iter(self).\n", + " | \n", + " | __le__(self, value, /)\n", + " | Return self<=value.\n", + " | \n", + " | __len__(self, /)\n", + " | Return len(self).\n", + " | \n", + " | __lt__(self, value, /)\n", + " | Return self integer -- return number of occurrences of value\n", + " | \n", + " | index(...)\n", + " | rangeobject.index(value) -> integer -- return index of value.\n", + " | Raise ValueError if the value is not present.\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods defined here:\n", + " | \n", + " | __new__(*args, **kwargs) from builtins.type\n", + " | Create and return a new object. See help(type) for accurate signature.\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors defined here:\n", + " | \n", + " | start\n", + " | \n", + " | step\n", + " | \n", + " | stop\n", + "\n" + ] + } + ], + "source": [ + "## Results from running help (range)\n", + "\n", + "f = list(range(0, 10))\n", + "help (range)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/untitled b/class_one/untitled new file mode 100644 index 0000000..e69de29 From 5d98e2c4102eee08b2c456f72b011c0dd5b9b5bf Mon Sep 17 00:00:00 2001 From: Lalla Sankara Date: Mon, 25 Mar 2024 20:56:40 -0700 Subject: [PATCH 5/6] jupyter notebook updates jupyter notebook updates --- .../02_strings-checkpoint.ipynb | 133 ++++++++++++++++++ .../03_functions-checkpoint.ipynb | 33 +++++ .../04_lists-checkpoint.ipynb | 33 +++++ .../05_loops_condtionals-checkpoint.ipynb | 33 +++++ .../06_dicts-checkpoint.ipynb | 33 +++++ class_one/02_strings.ipynb | 133 ++++++++++++++++++ class_one/03_functions.ipynb | 33 +++++ class_one/04_lists.ipynb | 33 +++++ class_one/05_loops_condtionals.ipynb | 33 +++++ class_one/06_dicts.ipynb | 33 +++++ class_one/untitled | 0 11 files changed, 530 insertions(+) create mode 100644 class_one/.ipynb_checkpoints/02_strings-checkpoint.ipynb create mode 100644 class_one/.ipynb_checkpoints/03_functions-checkpoint.ipynb create mode 100644 class_one/.ipynb_checkpoints/04_lists-checkpoint.ipynb create mode 100644 class_one/.ipynb_checkpoints/05_loops_condtionals-checkpoint.ipynb create mode 100644 class_one/.ipynb_checkpoints/06_dicts-checkpoint.ipynb create mode 100644 class_one/02_strings.ipynb create mode 100644 class_one/03_functions.ipynb create mode 100644 class_one/04_lists.ipynb create mode 100644 class_one/05_loops_condtionals.ipynb create mode 100644 class_one/06_dicts.ipynb delete mode 100644 class_one/untitled diff --git a/class_one/.ipynb_checkpoints/02_strings-checkpoint.ipynb b/class_one/.ipynb_checkpoints/02_strings-checkpoint.ipynb new file mode 100644 index 0000000..7bca453 --- /dev/null +++ b/class_one/.ipynb_checkpoints/02_strings-checkpoint.ipynb @@ -0,0 +1,133 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "eb84af51", + "metadata": {}, + "outputs": [], + "source": [ + "# STRINGS\n", + "# https://docs.python.org/3/tutorial/introduction.html#strings" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "74256b94", + "metadata": {}, + "outputs": [], + "source": [ + "s = str(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "f6ca2e83", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n", + "100\n" + ] + } + ], + "source": [ + "# convert another data type into a string (casting)\n", + "donut = str(100)\n", + "d = 'I like you'\n", + "print(s)\n", + "print(donut)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10c35e1e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "61d5a115", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "4895b4f2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# examine a string\n", + "s[0] # returns 'I'\n", + "\n", + "len(s) # returns 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a4f1c2c2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "182afbb0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8be6a6c2", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/.ipynb_checkpoints/03_functions-checkpoint.ipynb b/class_one/.ipynb_checkpoints/03_functions-checkpoint.ipynb new file mode 100644 index 0000000..7d84b3f --- /dev/null +++ b/class_one/.ipynb_checkpoints/03_functions-checkpoint.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "1f3947fc", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/.ipynb_checkpoints/04_lists-checkpoint.ipynb b/class_one/.ipynb_checkpoints/04_lists-checkpoint.ipynb new file mode 100644 index 0000000..3e9414e --- /dev/null +++ b/class_one/.ipynb_checkpoints/04_lists-checkpoint.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f4f50370", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/.ipynb_checkpoints/05_loops_condtionals-checkpoint.ipynb b/class_one/.ipynb_checkpoints/05_loops_condtionals-checkpoint.ipynb new file mode 100644 index 0000000..fb53600 --- /dev/null +++ b/class_one/.ipynb_checkpoints/05_loops_condtionals-checkpoint.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "8c5d1a48", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/.ipynb_checkpoints/06_dicts-checkpoint.ipynb b/class_one/.ipynb_checkpoints/06_dicts-checkpoint.ipynb new file mode 100644 index 0000000..754c9a1 --- /dev/null +++ b/class_one/.ipynb_checkpoints/06_dicts-checkpoint.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e779695a", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/02_strings.ipynb b/class_one/02_strings.ipynb new file mode 100644 index 0000000..7bca453 --- /dev/null +++ b/class_one/02_strings.ipynb @@ -0,0 +1,133 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "eb84af51", + "metadata": {}, + "outputs": [], + "source": [ + "# STRINGS\n", + "# https://docs.python.org/3/tutorial/introduction.html#strings" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "74256b94", + "metadata": {}, + "outputs": [], + "source": [ + "s = str(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "f6ca2e83", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n", + "100\n" + ] + } + ], + "source": [ + "# convert another data type into a string (casting)\n", + "donut = str(100)\n", + "d = 'I like you'\n", + "print(s)\n", + "print(donut)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10c35e1e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "61d5a115", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "4895b4f2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# examine a string\n", + "s[0] # returns 'I'\n", + "\n", + "len(s) # returns 10" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a4f1c2c2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "182afbb0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8be6a6c2", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/03_functions.ipynb b/class_one/03_functions.ipynb new file mode 100644 index 0000000..7d84b3f --- /dev/null +++ b/class_one/03_functions.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "1f3947fc", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/04_lists.ipynb b/class_one/04_lists.ipynb new file mode 100644 index 0000000..3e9414e --- /dev/null +++ b/class_one/04_lists.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "f4f50370", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/05_loops_condtionals.ipynb b/class_one/05_loops_condtionals.ipynb new file mode 100644 index 0000000..fb53600 --- /dev/null +++ b/class_one/05_loops_condtionals.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "8c5d1a48", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/06_dicts.ipynb b/class_one/06_dicts.ipynb new file mode 100644 index 0000000..754c9a1 --- /dev/null +++ b/class_one/06_dicts.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "e779695a", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/untitled b/class_one/untitled deleted file mode 100644 index e69de29..0000000 From 2a42330f0fc5c72787e25471e2627401f6f54f02 Mon Sep 17 00:00:00 2001 From: Lalla Sankara Date: Mon, 22 Apr 2024 01:00:21 -0700 Subject: [PATCH 6/6] class edits --- .../01_data_types.py-checkpoint.ipynb | 309 +++++++++++++++++ .../02_strings-checkpoint.ipynb | 304 ++++++++++++++-- .../03_functions-checkpoint.ipynb | 102 +++++- .../04_lists-checkpoint.ipynb | 49 ++- .../05_loops_condtionals-checkpoint.ipynb | 69 +++- .../06_dicts-checkpoint.ipynb | 50 ++- class_one/01_data_types.py.ipynb | 8 +- class_one/02_strings.ipynb | 328 ++++++++++++++++-- class_one/02_strings.py | 85 ----- class_one/03_functions.ipynb | 102 +++++- class_one/03_functions.py | 45 --- class_one/04_lists.ipynb | 49 ++- class_one/04_lists.py | 46 --- class_one/05_loops_conditionals.py | 66 ---- class_one/05_loops_condtionals.ipynb | 69 +++- class_one/06_dicts.ipynb | 50 ++- class_one/06_dicts.py | 47 --- 17 files changed, 1418 insertions(+), 360 deletions(-) create mode 100644 class_one/.ipynb_checkpoints/01_data_types.py-checkpoint.ipynb delete mode 100644 class_one/02_strings.py delete mode 100644 class_one/03_functions.py delete mode 100644 class_one/04_lists.py delete mode 100644 class_one/05_loops_conditionals.py delete mode 100644 class_one/06_dicts.py diff --git a/class_one/.ipynb_checkpoints/01_data_types.py-checkpoint.ipynb b/class_one/.ipynb_checkpoints/01_data_types.py-checkpoint.ipynb new file mode 100644 index 0000000..c577379 --- /dev/null +++ b/class_one/.ipynb_checkpoints/01_data_types.py-checkpoint.ipynb @@ -0,0 +1,309 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "da3d1fe2", + "metadata": {}, + "outputs": [], + "source": [ + "## Learn More Python with Automate the Boring Stuff:\n", + "## https://automatetheboringstuff.com/chapter1/\n", + "import numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "aca0980e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello world\n" + ] + } + ], + "source": [ + "# Your First Program\n", + "print('hello world')\n", + "# # Comments in python use a '#'\n", + "# # Remove the # in front of code to run it" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "67241b0e", + "metadata": {}, + "outputs": [], + "source": [ + "## WARM UP QUIZ\n", + "# PART I\n", + "a = 5\n", + "b = 5.0\n", + "c = a / 2\n", + "d = b / 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d0e7eafe", + "metadata": {}, + "outputs": [], + "source": [ + "# What is type(a)?\n", + "\n", + "# Its an integer" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d731210b", + "metadata": {}, + "outputs": [], + "source": [ + "# What is type(b)?\n", + "\n", + "# It is a float\n", + "\n", + "# What is c?\n", + "\n", + "# It is a float\n", + "\n", + "# What is d?\n", + "\n", + "# It is a float" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "246cb717", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# EXERCISES\n", + "e = [a, b]\n", + "f = list(range(0, 10))\n", + "(len(e))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f5967341", + "metadata": {}, + "outputs": [], + "source": [ + "# What is type(e)?\n", + "\n", + "# It's the data type list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f61a79e4", + "metadata": {}, + "outputs": [], + "source": [ + "# What is len(e)?\n", + "\n", + "# len (e) give the length of the list which is 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "54cfa5e5", + "metadata": {}, + "outputs": [], + "source": [ + "# What is type(f)?\n", + "\n", + "# Its the data type list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "46afebcc", + "metadata": {}, + "outputs": [], + "source": [ + "# What are the contents of f?\n", + "\n", + "# The contents are [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "25150070", + "metadata": {}, + "outputs": [], + "source": [ + "# What is 'list' called? # hint: google it\n", + "\n", + "# A list is simply called list in python. A list is used to store collections of items, \n", + "# where each item in the list can be of any data type, and the items are\n", + "# ordered and mutable." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de3294c3", + "metadata": {}, + "outputs": [], + "source": [ + "# What is 'range' called? What happens when you run 'help(range)'?\n", + "\n", + "# In python range is a built in function. It's used to generate a sequence of numbers.\n", + "# When you run help(range) in Python, it displays information about the range function, including its usage,\n", + "# parameters, and return value" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "006dbc75", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on class range in module builtins:\n", + "\n", + "class range(object)\n", + " | range(stop) -> range object\n", + " | range(start, stop[, step]) -> range object\n", + " | \n", + " | Return an object that produces a sequence of integers from start (inclusive)\n", + " | to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1.\n", + " | start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3.\n", + " | These are exactly the valid indices for a list of 4 elements.\n", + " | When step is given, it specifies the increment (or decrement).\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | __bool__(self, /)\n", + " | True if self else False\n", + " | \n", + " | __contains__(self, key, /)\n", + " | Return key in self.\n", + " | \n", + " | __eq__(self, value, /)\n", + " | Return self==value.\n", + " | \n", + " | __ge__(self, value, /)\n", + " | Return self>=value.\n", + " | \n", + " | __getattribute__(self, name, /)\n", + " | Return getattr(self, name).\n", + " | \n", + " | __getitem__(self, key, /)\n", + " | Return self[key].\n", + " | \n", + " | __gt__(self, value, /)\n", + " | Return self>value.\n", + " | \n", + " | __hash__(self, /)\n", + " | Return hash(self).\n", + " | \n", + " | __iter__(self, /)\n", + " | Implement iter(self).\n", + " | \n", + " | __le__(self, value, /)\n", + " | Return self<=value.\n", + " | \n", + " | __len__(self, /)\n", + " | Return len(self).\n", + " | \n", + " | __lt__(self, value, /)\n", + " | Return self integer -- return number of occurrences of value\n", + " | \n", + " | index(...)\n", + " | rangeobject.index(value) -> integer -- return index of value.\n", + " | Raise ValueError if the value is not present.\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods defined here:\n", + " | \n", + " | __new__(*args, **kwargs) from builtins.type\n", + " | Create and return a new object. See help(type) for accurate signature.\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors defined here:\n", + " | \n", + " | start\n", + " | \n", + " | step\n", + " | \n", + " | stop\n", + "\n" + ] + } + ], + "source": [ + "## Results from running help (range)\n", + "\n", + "f = list(range(0, 10))\n", + "help (range)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/class_one/.ipynb_checkpoints/02_strings-checkpoint.ipynb b/class_one/.ipynb_checkpoints/02_strings-checkpoint.ipynb index 7bca453..cfeabf7 100644 --- a/class_one/.ipynb_checkpoints/02_strings-checkpoint.ipynb +++ b/class_one/.ipynb_checkpoints/02_strings-checkpoint.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "eb84af51", "metadata": {}, "outputs": [], @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 7, "id": "74256b94", "metadata": {}, "outputs": [], @@ -23,71 +23,277 @@ }, { "cell_type": "code", - "execution_count": 14, - "id": "f6ca2e83", + "execution_count": 8, + "id": "86575085", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "42\n", - "100\n" - ] + "data": { + "text/plain": [ + "'42'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "# convert another data type into a string (casting)\n", - "donut = str(100)\n", - "d = 'I like you'\n", - "print(s)\n", - "print(donut)" + "s # convert another data type into a string (casting)" ] }, { "cell_type": "code", - "execution_count": null, - "id": "10c35e1e", + "execution_count": 9, + "id": "42fb71d8", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "s = 'I like you'" + ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, + "id": "10c35e1e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# examine a string\n", + "s[0] # returns 'I'" + ] + }, + { + "cell_type": "code", + "execution_count": 13, "id": "61d5a115", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(s) # returns 10" + ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 14, "id": "4895b4f2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2" + "'I like '" ] }, - "execution_count": 4, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# examine a string\n", - "s[0] # returns 'I'\n", + "# string slicing like lists\n", + "s[0:7] # returns 'I like '" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a4f1c2c2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' you'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s[6:] # returns 'you'" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "182afbb0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'u'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s[-1] # returns 'u'" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "de0839fc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"'I like '\"" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Use the 'repr()'\n", + "# repr() is string representation\n", + "repr(s[0:7])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "815f3b0b", + "metadata": {}, + "outputs": [], + "source": [ + "# EXERCISE: Book Titles (Part 1)\n", + "# 1) Extract the book title from the string\n", + "# 2) Save each book title to a variable (ie book1_title)\n", + "# 3) How many characters/elements are in each title?\n", + "# Hint: {bookTitle} by {author}, {years}\n", + "\n", "\n", - "len(s) # returns 10" + "book1 = \"Beyond the Door by Dick, Philip K., 1928-1982\"\n", + "book2 = \"The Variable Man by Dick, Philip K., 1928-1982\"\n", + "book3 = \"The Skull by Dick, Philip K., 1928-1982\"" ] }, { "cell_type": "code", "execution_count": null, - "id": "a4f1c2c2", + "id": "9ee05348", + "metadata": {}, + "outputs": [], + "source": [ + "# 1) Extract the book title from the string\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e52f485", + "metadata": {}, + "outputs": [], + "source": [ + "# 2) Save each book title to a variable (ie book1_title)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "37bf1de3", + "metadata": {}, + "outputs": [], + "source": [ + "# 3) How many characters/elements are in each title?\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fe06bbbf", + "metadata": {}, + "outputs": [], + "source": [ + "# STRINGS - Part II\n", + "\n", + "# concatenate strings\n", + "s3 = 'The meaning of life is'\n", + "s4 = '42'\n", + "s3 + ' ' + s4 # returns 'The meaning of life is 42'\n", + "s3 + ' ' + str(42) # same thing" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7e1f6bdf", + "metadata": {}, + "outputs": [], + "source": [ + "# split a string into a list of substrings separated by a delimiter\n", + "\n", + "s = 'I like you'\n", + "s.split(' ') # returns ['I','like','you']\n", + "s.split() # same thing\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2cb1c0d", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# Reverse a string\n", + "\n", + "string = 'Hello, my friend!' \n", + "\n", + "string[::-1]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c0d47304", + "metadata": {}, + "outputs": [], + "source": [ + "# Replace substring with another value\n", + "\n", + "cheese_str = 'I like yummy cheese'\n", + "\n", + "cheese_str.replace('like', 'love')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2efce121", "metadata": {}, "outputs": [], "source": [] @@ -95,7 +301,7 @@ { "cell_type": "code", "execution_count": null, - "id": "182afbb0", + "id": "d4de21e2", "metadata": {}, "outputs": [], "source": [] @@ -103,10 +309,48 @@ { "cell_type": "code", "execution_count": null, - "id": "8be6a6c2", + "id": "2cee970a", "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0052a674", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8be6a6c2", + "metadata": {}, + "outputs": [], + "source": [ + "# BONUS EXERCISE - \tPalindrome Detection\n", + "# A palindrome is a word, phrase, number or sequence of words that \n", + "# reads the same backwards as forwards. \n", + "# Punctuation and spaces between the words or lettering is allowed. \n", + "\n", + "# 1) Can you programmatically test if these phrases are palindromes?\n", + "\n", + "palindrome_one = 'racecar'\n", + "\n", + "\n", + "palindrome_two = 'step on no pets' \n", + "\n", + "\n", + "palindrome_three = 'Red rum, sir, is murder!' \n", + "\n", + "# hint - how can you lowercase a string?\n", + "# hint - how can you remove / replace punctuation with an empty string?\n", + "# Next level exercise - see 03_functions.py\n", + "\n", + "## Learn more with Automate the Boring Stuff:\n", + "## https://automatetheboringstuff.com/chapter1/" + ] } ], "metadata": { diff --git a/class_one/.ipynb_checkpoints/03_functions-checkpoint.ipynb b/class_one/.ipynb_checkpoints/03_functions-checkpoint.ipynb index 7d84b3f..7c97134 100644 --- a/class_one/.ipynb_checkpoints/03_functions-checkpoint.ipynb +++ b/class_one/.ipynb_checkpoints/03_functions-checkpoint.ipynb @@ -2,10 +2,110 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "1f3947fc", "metadata": {}, "outputs": [], + "source": [ + "# FUNCTIONS\n", + "# A function is like a mini-program within a program.\n", + "def hello():\n", + " print('Howdy!')\n", + " print('Howdy!!!')\n", + " print('Hello there.')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "40893b94", + "metadata": {}, + "outputs": [], + "source": [ + "# Can you run the function hello()?\n", + "def hello_friend(name):\n", + " print('Howdy, ' + name)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "edbcc056", + "metadata": {}, + "outputs": [], + "source": [ + "# Can you say Howdy to your code buddy?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "715cb1d6", + "metadata": {}, + "outputs": [], + "source": [ + "### Exercise: Can you write a function that:\n", + "# Takes in your name and the language you are learning\n", + "# Prints out an Introduction for yourself\n", + "# Bonus -- if you are learning 'python', then it prints out 'Cool!'\n", + "# Hint - google python 'if' statement" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "91a50e84", + "metadata": {}, + "outputs": [], + "source": [ + "### Bonus Exercise: Extra Credit\n", + "# Write a Palindrome Detection function\n", + "# Takes in a string and returns a boolean if the string is a palindrome\n", + "# Hint: It might require some data cleaning, check out 02_strings.py\n", + "# Hint: google 'python boolean equality'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42079680", + "metadata": {}, + "outputs": [], + "source": [ + "palindrome_one = 'racecar'\n", + "\n", + "\n", + "palindrome_two = 'step on no pets' \n", + "\n", + "\n", + "palindrome_three = 'Red rum, sir, is murder!' " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2284ed3", + "metadata": {}, + "outputs": [], + "source": [ + "### Learn More About Functions\n", + "# https://automatetheboringstuff.com/chapter3/" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e82f84bc", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34ef0d8f", + "metadata": {}, + "outputs": [], "source": [] } ], diff --git a/class_one/.ipynb_checkpoints/04_lists-checkpoint.ipynb b/class_one/.ipynb_checkpoints/04_lists-checkpoint.ipynb index 3e9414e..c14d0ce 100644 --- a/class_one/.ipynb_checkpoints/04_lists-checkpoint.ipynb +++ b/class_one/.ipynb_checkpoints/04_lists-checkpoint.ipynb @@ -6,7 +6,54 @@ "id": "f4f50370", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# LISTS\n", + "# https://docs.python.org/3/tutorial/introduction.html#lists\n", + "\n", + "# list slicing [start:end:stride]\n", + "\n", + "weekdays = ['mon','tues','wed','thurs','fri']\n", + "weekdays[0] # element 0\n", + "weekdays[0:3] # elements 0, 1, 2\n", + "weekdays[:3] # elements 0, 1, 2\n", + "weekdays[-1] # last element\n", + "\n", + "test = weekdays[3:] # elements 3, 4\n", + "\n", + "weekdays\n", + "\n", + "weekdays[-2] # last element (element 4)\n", + "weekdays[::2] # every 2nd element (0, 2, 4)\n", + "weekdays[::-1] # backwards (4, 3, 2, 1, 0)\n", + "\n", + "days = weekdays + ['sat','sun'] # concatenate lists\n", + "\n", + "# Let's look at it another way\n", + "days_list = ['mon','tues','wed','thurs','fri']\n", + "days_list.append('sat') # append individual elements to list\n", + "days_list.append('sun')\n", + "\n", + "#########\n", + "# Exercise - Lists\n", + "#########\n", + "\n", + "# How do I select 'wed' by index?\n", + "\n", + "\n", + "# How do I check the type of 'mon'?\n", + "\n", + "\n", + "# How do I slice out 'wed' through 'friday'?\n", + "\n", + "\n", + "# What are two ways to select 'fri' by index?\n", + "\n", + "\n", + "# What is the length of days and days_list?\n", + "\n", + "\n", + "# How do I reverse the order of days? (hint: google it)" + ] } ], "metadata": { diff --git a/class_one/.ipynb_checkpoints/05_loops_condtionals-checkpoint.ipynb b/class_one/.ipynb_checkpoints/05_loops_condtionals-checkpoint.ipynb index fb53600..894865d 100644 --- a/class_one/.ipynb_checkpoints/05_loops_condtionals-checkpoint.ipynb +++ b/class_one/.ipynb_checkpoints/05_loops_condtionals-checkpoint.ipynb @@ -6,7 +6,74 @@ "id": "8c5d1a48", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "## FOR LOOPS\n", + "\n", + "# print 0 through 5 on a separate line\n", + "nums = [0, 1, 3, 4, 5]\n", + "\n", + "for num in nums:\n", + " print(num)\n", + "\n", + "# for loop to create a list of cubes\n", + "cubes = []\n", + "for num in nums:\n", + " cubes.append(num ** 3)\n", + "\n", + "\n", + "##### CONDITIONALS ######\n", + "\n", + "# We will use an if else to implement logic\n", + "x = 15\n", + "if x > 10:\n", + " print(\"x is more than 10!\")\n", + " print(\"hooray\")\n", + "elif x > 100:\n", + " print(\"x is HUGE\")\n", + "\n", + "# As soon as one conditional is satisfied, it stops checking!\n", + "\n", + "temperature = 20\n", + "if temperature <= 32:\n", + " print(\"water is ice\")\n", + "elif temperature > 32 and temperature < 212:\n", + " print(\"water is liquid\")\n", + "else: # implicity means else if temperature >=212\n", + " print(\"water will boil\")\n", + "\n", + "\n", + "## LIST COMPREHENSIONS WITH CONDITIONS\n", + "# range when passed to a list, produces a range of numbers\n", + "\n", + "nums = list(range(1, 6))\n", + "\n", + "# for loop to create a list of cubes of even numbers\n", + "cubes_of_even = []\n", + "for num in nums:\n", + " if num % 2 == 0:\n", + " cubes_of_even.append(num ** 3)\n", + "\n", + "# equivalent list comprehension\n", + "# syntax: [expression for variable in iterable if condition]\n", + "\n", + "cubes_of_even = [num ** 3 for num in nums if num % 2 == 0] # [8, 64]\n", + "\n", + "\n", + "#########\n", + "# EXERCISE For Loops\n", + "#########\n", + "# Given that: letters = ['a','b','c']\n", + "# Write a for-loop that returns: ['A','B','C']\n", + "\n", + "\n", + "# Given that: nums = [0, 1, 3, 4, 5]\n", + "# Write a for-loop that sums the total of all the numbers in the list\n", + "\n", + "\n", + "# Given that: nums = [0, 1, 3, 4, 5]\n", + "# Write a for-loop that prints out even numbers\n", + "\n" + ] } ], "metadata": { diff --git a/class_one/.ipynb_checkpoints/06_dicts-checkpoint.ipynb b/class_one/.ipynb_checkpoints/06_dicts-checkpoint.ipynb index 754c9a1..7869cc8 100644 --- a/class_one/.ipynb_checkpoints/06_dicts-checkpoint.ipynb +++ b/class_one/.ipynb_checkpoints/06_dicts-checkpoint.ipynb @@ -6,7 +6,55 @@ "id": "e779695a", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "## DICTIONARIES\n", + "\n", + "# dictionaries are similar to lists:\n", + "# - both can contain multiple data types\n", + "# - both are iterable\n", + "# - both are mutable\n", + "\n", + "# dictionaries are different from lists:\n", + "# - dictionaries are unordered*\n", + "# - dictionary lookup time is constant regardless of dictionary size\n", + "\n", + "# dictionaries are like real dictionaries:\n", + "# - dictionaries are made of key-value pairs (word and definition)\n", + "# - dictionary keys must be unique (each word is only defined once)\n", + "# - you can use the key to look up the value, but not the other way around\n", + "\n", + "# create a dictionary (and open Variable Explorer in Spyder)\n", + "family = {'dad':'homer', 'mom':'marge', 'size':6}\n", + "\n", + "# examine a dictionary\n", + "# family[0] # throws an error (there is no ordering)\n", + "family['dad'] # returns 'homer'\n", + "len(family) # returns 3\n", + "family.keys() # returns list: ['dad', 'mom', 'size']\n", + "family.values() # returns list: ['homer', 'marge', 6]\n", + "family.items() # returns list of tuples:\n", + " # [('dad', 'homer'), ('mom', 'marge'), ('size', 6)]\n", + "\n", + "# modify a dictionary\n", + "family['cat'] = 'snowball' # add a new entry\n", + "family['cat'] = 'snowball ii' # edit an existing entry\n", + "del family['cat'] # delete an entry\n", + "family['kids'] = ['bart', 'lisa'] # value can be a list\n", + "\n", + "# accessing a list element within a dictionary\n", + "family['kids'][0] # returns 'bart'\n", + "\n", + "# EXERCISE:\n", + "# Given that: d = {'a':10, 'b':20, 'c':[30, 40]}\n", + "\n", + "# First, print the value for 'a'\n", + "\n", + "# Then, change the value for 'b' to be 25\n", + "\n", + "# Then, change the 30 to be 35\n", + "\n", + "# Finally, append 45 to the end of the list that contains 35 and 40\n" + ] } ], "metadata": { diff --git a/class_one/01_data_types.py.ipynb b/class_one/01_data_types.py.ipynb index d1184ed..c577379 100644 --- a/class_one/01_data_types.py.ipynb +++ b/class_one/01_data_types.py.ipynb @@ -62,22 +62,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "d731210b", "metadata": {}, "outputs": [], "source": [ "# What is type(b)?\n", "\n", - "# Its a float\n", + "# It is a float\n", "\n", "# What is c?\n", "\n", - "# ITs a float\n", + "# It is a float\n", "\n", "# What is d?\n", "\n", - "# Its a float" + "# It is a float" ] }, { diff --git a/class_one/02_strings.ipynb b/class_one/02_strings.ipynb index 7bca453..8473b52 100644 --- a/class_one/02_strings.ipynb +++ b/class_one/02_strings.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "eb84af51", "metadata": {}, "outputs": [], @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 7, "id": "74256b94", "metadata": {}, "outputs": [], @@ -21,81 +21,351 @@ "s = str(42)" ] }, + { + "cell_type": "code", + "execution_count": 8, + "id": "89f95f81", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'42'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s # convert another data type into a string (casting)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "32b17417", + "metadata": {}, + "outputs": [], + "source": [ + "s = 'I like you'" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "10c35e1e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# examine a string\n", + "s[0] # returns 'I'" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "61d5a115", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(s) # returns 10" + ] + }, { "cell_type": "code", "execution_count": 14, - "id": "f6ca2e83", + "id": "4895b4f2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I like '" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# string slicing like lists\n", + "s[0:7] # returns 'I like '" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a4f1c2c2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' you'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s[6:] # returns 'you'" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "182afbb0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'u'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s[-1] # returns 'u'" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "b00b69e4", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "42\n", - "100\n" - ] + "data": { + "text/plain": [ + "\"'I like '\"" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "# convert another data type into a string (casting)\n", - "donut = str(100)\n", - "d = 'I like you'\n", - "print(s)\n", - "print(donut)" + "# Use the 'repr()'\n", + "# repr() is string representation\n", + "repr(s[0:7])" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "87f3e216", + "metadata": {}, + "outputs": [], + "source": [ + "# EXERCISE: Book Titles (Part 1)\n", + "# 1) Extract the book title from the string\n", + "# 2) Save each book title to a variable (ie book1_title)\n", + "# 3) How many characters/elements are in each title?\n", + "# Hint: {bookTitle} by {author}, {years}\n", + "\n", + "\n", + "book1 = \"Beyond the Door by Dick, Philip K., 1928-1982\"\n", + "book2 = \"The Variable Man by Dick, Philip K., 1928-1982\"\n", + "book3 = \"The Skull by Dick, Philip K., 1928-1982\"" ] }, { "cell_type": "code", "execution_count": null, - "id": "10c35e1e", + "id": "1db679cb", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# 1) Extract the book title from the string\n" + ] }, { "cell_type": "code", "execution_count": null, - "id": "61d5a115", + "id": "dc2091d8", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# 2) Save each book title to a variable (ie book1_title)\n" + ] }, { "cell_type": "code", - "execution_count": 4, - "id": "4895b4f2", + "execution_count": null, + "id": "b09af200", + "metadata": {}, + "outputs": [], + "source": [ + "# 3) How many characters/elements are in each title?\n" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "63e220e2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2" + "'The meaning of life is 42'" ] }, - "execution_count": 4, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# examine a string\n", - "s[0] # returns 'I'\n", + "# STRINGS - Part II\n", + "# concatenate strings\n", + "s3 = 'The meaning of life is'\n", + "s4 = '42'\n", + "s3 + ' ' + s4 # returns 'The meaning of life is 42'\n", + "s3 + ' ' + str(42) # same thing" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "9f6e577b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['I', 'like', 'you']" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# split a string into a list of substrings separated by a delimiter\n", "\n", - "len(s) # returns 10" + "s = 'I like you'\n", + "s.split(' ') # returns ['I','like','you']\n", + "s.split() # same thing\n" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "aebedf2b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'!dneirf ym ,olleH'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Reverse a string\n", + "\n", + "string = 'Hello, my friend!' \n", + "\n", + "string[::-1]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "816e4c00", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I love yummy cheese'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Replace substring with another value\n", + "\n", + "cheese_str = 'I like yummy cheese'\n", + "\n", + "cheese_str.replace('like', 'love')" ] }, { "cell_type": "code", "execution_count": null, - "id": "a4f1c2c2", + "id": "8be6a6c2", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# BONUS EXERCISE - \tPalindrome Detection\n", + "# A palindrome is a word, phrase, number or sequence of words that \n", + "# reads the same backwards as forwards. \n", + "# Punctuation and spaces between the words or lettering is allowed. \n", + "\n", + "# 1) Can you programmatically test if these phrases are palindromes?\n", + "\n", + "palindrome_one = 'racecar'\n", + "\n", + "\n", + "palindrome_two = 'step on no pets' \n", + "\n", + "\n", + "palindrome_three = 'Red rum, sir, is murder!' \n", + "\n", + "# hint - how can you lowercase a string?\n", + "# hint - how can you remove / replace punctuation with an empty string?\n", + "# Next level exercise - see 03_functions.py\n", + "\n", + "## Learn more with Automate the Boring Stuff:\n", + "## https://automatetheboringstuff.com/chapter1/" + ] }, { "cell_type": "code", "execution_count": null, - "id": "182afbb0", + "id": "5f4e6db1", "metadata": {}, "outputs": [], "source": [] @@ -103,7 +373,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8be6a6c2", + "id": "b891f15c", "metadata": {}, "outputs": [], "source": [] diff --git a/class_one/02_strings.py b/class_one/02_strings.py deleted file mode 100644 index 5d982c1..0000000 --- a/class_one/02_strings.py +++ /dev/null @@ -1,85 +0,0 @@ -# STRINGS -# https://docs.python.org/3/tutorial/introduction.html#strings - -s = str(42) - -s # convert another data type into a string (casting) - -s = 'I like you' - -# examine a string -s[0] # returns 'I' - -len(s) # returns 10 - -# string slicing like lists -s[0:7] # returns 'I like ' - -s[6:] # returns 'you' - -s[-1] # returns 'u' - -# Use the 'repr()' -# repr() is string representation -repr(s[0:7]) - -# EXERCISE: Book Titles (Part 1) -# 1) Extract the book title from the string -# 2) Save each book title to a variable (ie book1_title) -# 3) How many characters/elements are in each title? -# Hint: {bookTitle} by {author}, {years} - - -book1 = "Beyond the Door by Dick, Philip K., 1928-1982" -book2 = "The Variable Man by Dick, Philip K., 1928-1982" -book3 = "The Skull by Dick, Philip K., 1928-1982" - - -# STRINGS - Part II - -# concatenate strings -s3 = 'The meaning of life is' -s4 = '42' -s3 + ' ' + s4 # returns 'The meaning of life is 42' -s3 + ' ' + str(42) # same thing - -# split a string into a list of substrings separated by a delimiter - -s = 'I like you' -s.split(' ') # returns ['I','like','you'] -s.split() # same thing - -# Reverse a string - -string = 'Hello, my friend!' - -string[::-1] - -# Replace substring with another value - -cheese_str = 'I like yummy cheese' - -cheese_str.replace('like', 'love') - - -# BONUS EXERCISE - Palindrome Detection -# A palindrome is a word, phrase, number or sequence of words that -# reads the same backwards as forwards. -# Punctuation and spaces between the words or lettering is allowed. - -# 1) Can you programmatically test if these phrases are palindromes? - -palindrome_one = 'racecar' - - -palindrome_two = 'step on no pets' - - -palindrome_three = 'Red rum, sir, is murder!' - -# hint - how can you lowercase a string? -# hint - how can you remove / replace punctuation with an empty string? -# Next level exercise - see 03_functions.py - -## Learn more with Automate the Boring Stuff: -## https://automatetheboringstuff.com/chapter1/ \ No newline at end of file diff --git a/class_one/03_functions.ipynb b/class_one/03_functions.ipynb index 7d84b3f..7c97134 100644 --- a/class_one/03_functions.ipynb +++ b/class_one/03_functions.ipynb @@ -2,10 +2,110 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "1f3947fc", "metadata": {}, "outputs": [], + "source": [ + "# FUNCTIONS\n", + "# A function is like a mini-program within a program.\n", + "def hello():\n", + " print('Howdy!')\n", + " print('Howdy!!!')\n", + " print('Hello there.')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "40893b94", + "metadata": {}, + "outputs": [], + "source": [ + "# Can you run the function hello()?\n", + "def hello_friend(name):\n", + " print('Howdy, ' + name)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "edbcc056", + "metadata": {}, + "outputs": [], + "source": [ + "# Can you say Howdy to your code buddy?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "715cb1d6", + "metadata": {}, + "outputs": [], + "source": [ + "### Exercise: Can you write a function that:\n", + "# Takes in your name and the language you are learning\n", + "# Prints out an Introduction for yourself\n", + "# Bonus -- if you are learning 'python', then it prints out 'Cool!'\n", + "# Hint - google python 'if' statement" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "91a50e84", + "metadata": {}, + "outputs": [], + "source": [ + "### Bonus Exercise: Extra Credit\n", + "# Write a Palindrome Detection function\n", + "# Takes in a string and returns a boolean if the string is a palindrome\n", + "# Hint: It might require some data cleaning, check out 02_strings.py\n", + "# Hint: google 'python boolean equality'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42079680", + "metadata": {}, + "outputs": [], + "source": [ + "palindrome_one = 'racecar'\n", + "\n", + "\n", + "palindrome_two = 'step on no pets' \n", + "\n", + "\n", + "palindrome_three = 'Red rum, sir, is murder!' " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2284ed3", + "metadata": {}, + "outputs": [], + "source": [ + "### Learn More About Functions\n", + "# https://automatetheboringstuff.com/chapter3/" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e82f84bc", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34ef0d8f", + "metadata": {}, + "outputs": [], "source": [] } ], diff --git a/class_one/03_functions.py b/class_one/03_functions.py deleted file mode 100644 index 152ee0d..0000000 --- a/class_one/03_functions.py +++ /dev/null @@ -1,45 +0,0 @@ - -# FUNCTIONS - -# A function is like a mini-program within a program. -def hello(): - print('Howdy!') - print('Howdy!!!') - print('Hello there.') - -# Can you run the function hello()? - - -def hello_friend(name): - print('Howdy, ' + name) - -# Can you say Howdy to your code buddy? - - -### Exercise: Can you write a function that: -# Takes in your name and the language you are learning -# Prints out an Introduction for yourself -# Bonus -- if you are learning 'python', then it prints out 'Cool!' -# Hint - google python 'if' statement - - -### Bonus Exercise: Extra Credit -# Write a Palindrome Detection function -# Takes in a string and returns a boolean if the string is a palindrome -# Hint: It might require some data cleaning, check out 02_strings.py -# Hint: google 'python boolean equality' - -palindrome_one = 'racecar' - - -palindrome_two = 'step on no pets' - - -palindrome_three = 'Red rum, sir, is murder!' - - - - -### Learn More About Functions -# https://automatetheboringstuff.com/chapter3/ - diff --git a/class_one/04_lists.ipynb b/class_one/04_lists.ipynb index 3e9414e..c14d0ce 100644 --- a/class_one/04_lists.ipynb +++ b/class_one/04_lists.ipynb @@ -6,7 +6,54 @@ "id": "f4f50370", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# LISTS\n", + "# https://docs.python.org/3/tutorial/introduction.html#lists\n", + "\n", + "# list slicing [start:end:stride]\n", + "\n", + "weekdays = ['mon','tues','wed','thurs','fri']\n", + "weekdays[0] # element 0\n", + "weekdays[0:3] # elements 0, 1, 2\n", + "weekdays[:3] # elements 0, 1, 2\n", + "weekdays[-1] # last element\n", + "\n", + "test = weekdays[3:] # elements 3, 4\n", + "\n", + "weekdays\n", + "\n", + "weekdays[-2] # last element (element 4)\n", + "weekdays[::2] # every 2nd element (0, 2, 4)\n", + "weekdays[::-1] # backwards (4, 3, 2, 1, 0)\n", + "\n", + "days = weekdays + ['sat','sun'] # concatenate lists\n", + "\n", + "# Let's look at it another way\n", + "days_list = ['mon','tues','wed','thurs','fri']\n", + "days_list.append('sat') # append individual elements to list\n", + "days_list.append('sun')\n", + "\n", + "#########\n", + "# Exercise - Lists\n", + "#########\n", + "\n", + "# How do I select 'wed' by index?\n", + "\n", + "\n", + "# How do I check the type of 'mon'?\n", + "\n", + "\n", + "# How do I slice out 'wed' through 'friday'?\n", + "\n", + "\n", + "# What are two ways to select 'fri' by index?\n", + "\n", + "\n", + "# What is the length of days and days_list?\n", + "\n", + "\n", + "# How do I reverse the order of days? (hint: google it)" + ] } ], "metadata": { diff --git a/class_one/04_lists.py b/class_one/04_lists.py deleted file mode 100644 index 3d4cd3c..0000000 --- a/class_one/04_lists.py +++ /dev/null @@ -1,46 +0,0 @@ -# LISTS -# https://docs.python.org/3/tutorial/introduction.html#lists - -# list slicing [start:end:stride] - -weekdays = ['mon','tues','wed','thurs','fri'] -weekdays[0] # element 0 -weekdays[0:3] # elements 0, 1, 2 -weekdays[:3] # elements 0, 1, 2 -weekdays[-1] # last element - -test = weekdays[3:] # elements 3, 4 - -weekdays - -weekdays[-2] # last element (element 4) -weekdays[::2] # every 2nd element (0, 2, 4) -weekdays[::-1] # backwards (4, 3, 2, 1, 0) - -days = weekdays + ['sat','sun'] # concatenate lists - -# Let's look at it another way -days_list = ['mon','tues','wed','thurs','fri'] -days_list.append('sat') # append individual elements to list -days_list.append('sun') - -######### -# Exercise - Lists -######### - -# How do I select 'wed' by index? - - -# How do I check the type of 'mon'? - - -# How do I slice out 'wed' through 'friday'? - - -# What are two ways to select 'fri' by index? - - -# What is the length of days and days_list? - - -# How do I reverse the order of days? (hint: google it) \ No newline at end of file diff --git a/class_one/05_loops_conditionals.py b/class_one/05_loops_conditionals.py deleted file mode 100644 index 908edad..0000000 --- a/class_one/05_loops_conditionals.py +++ /dev/null @@ -1,66 +0,0 @@ -## FOR LOOPS - -# print 0 through 5 on a separate line -nums = [0, 1, 3, 4, 5] - -for num in nums: - print(num) - -# for loop to create a list of cubes -cubes = [] -for num in nums: - cubes.append(num ** 3) - - -##### CONDITIONALS ###### - -# We will use an if else to implement logic -x = 15 -if x > 10: - print("x is more than 10!") - print("hooray") -elif x > 100: - print("x is HUGE") - -# As soon as one conditional is satisfied, it stops checking! - -temperature = 20 -if temperature <= 32: - print("water is ice") -elif temperature > 32 and temperature < 212: - print("water is liquid") -else: # implicity means else if temperature >=212 - print("water will boil") - - -## LIST COMPREHENSIONS WITH CONDITIONS -# range when passed to a list, produces a range of numbers - -nums = list(range(1, 6)) - -# for loop to create a list of cubes of even numbers -cubes_of_even = [] -for num in nums: - if num % 2 == 0: - cubes_of_even.append(num ** 3) - -# equivalent list comprehension -# syntax: [expression for variable in iterable if condition] - -cubes_of_even = [num ** 3 for num in nums if num % 2 == 0] # [8, 64] - - -######### -# EXERCISE For Loops -######### -# Given that: letters = ['a','b','c'] -# Write a for-loop that returns: ['A','B','C'] - - -# Given that: nums = [0, 1, 3, 4, 5] -# Write a for-loop that sums the total of all the numbers in the list - - -# Given that: nums = [0, 1, 3, 4, 5] -# Write a for-loop that prints out even numbers - diff --git a/class_one/05_loops_condtionals.ipynb b/class_one/05_loops_condtionals.ipynb index fb53600..894865d 100644 --- a/class_one/05_loops_condtionals.ipynb +++ b/class_one/05_loops_condtionals.ipynb @@ -6,7 +6,74 @@ "id": "8c5d1a48", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "## FOR LOOPS\n", + "\n", + "# print 0 through 5 on a separate line\n", + "nums = [0, 1, 3, 4, 5]\n", + "\n", + "for num in nums:\n", + " print(num)\n", + "\n", + "# for loop to create a list of cubes\n", + "cubes = []\n", + "for num in nums:\n", + " cubes.append(num ** 3)\n", + "\n", + "\n", + "##### CONDITIONALS ######\n", + "\n", + "# We will use an if else to implement logic\n", + "x = 15\n", + "if x > 10:\n", + " print(\"x is more than 10!\")\n", + " print(\"hooray\")\n", + "elif x > 100:\n", + " print(\"x is HUGE\")\n", + "\n", + "# As soon as one conditional is satisfied, it stops checking!\n", + "\n", + "temperature = 20\n", + "if temperature <= 32:\n", + " print(\"water is ice\")\n", + "elif temperature > 32 and temperature < 212:\n", + " print(\"water is liquid\")\n", + "else: # implicity means else if temperature >=212\n", + " print(\"water will boil\")\n", + "\n", + "\n", + "## LIST COMPREHENSIONS WITH CONDITIONS\n", + "# range when passed to a list, produces a range of numbers\n", + "\n", + "nums = list(range(1, 6))\n", + "\n", + "# for loop to create a list of cubes of even numbers\n", + "cubes_of_even = []\n", + "for num in nums:\n", + " if num % 2 == 0:\n", + " cubes_of_even.append(num ** 3)\n", + "\n", + "# equivalent list comprehension\n", + "# syntax: [expression for variable in iterable if condition]\n", + "\n", + "cubes_of_even = [num ** 3 for num in nums if num % 2 == 0] # [8, 64]\n", + "\n", + "\n", + "#########\n", + "# EXERCISE For Loops\n", + "#########\n", + "# Given that: letters = ['a','b','c']\n", + "# Write a for-loop that returns: ['A','B','C']\n", + "\n", + "\n", + "# Given that: nums = [0, 1, 3, 4, 5]\n", + "# Write a for-loop that sums the total of all the numbers in the list\n", + "\n", + "\n", + "# Given that: nums = [0, 1, 3, 4, 5]\n", + "# Write a for-loop that prints out even numbers\n", + "\n" + ] } ], "metadata": { diff --git a/class_one/06_dicts.ipynb b/class_one/06_dicts.ipynb index 754c9a1..7869cc8 100644 --- a/class_one/06_dicts.ipynb +++ b/class_one/06_dicts.ipynb @@ -6,7 +6,55 @@ "id": "e779695a", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "## DICTIONARIES\n", + "\n", + "# dictionaries are similar to lists:\n", + "# - both can contain multiple data types\n", + "# - both are iterable\n", + "# - both are mutable\n", + "\n", + "# dictionaries are different from lists:\n", + "# - dictionaries are unordered*\n", + "# - dictionary lookup time is constant regardless of dictionary size\n", + "\n", + "# dictionaries are like real dictionaries:\n", + "# - dictionaries are made of key-value pairs (word and definition)\n", + "# - dictionary keys must be unique (each word is only defined once)\n", + "# - you can use the key to look up the value, but not the other way around\n", + "\n", + "# create a dictionary (and open Variable Explorer in Spyder)\n", + "family = {'dad':'homer', 'mom':'marge', 'size':6}\n", + "\n", + "# examine a dictionary\n", + "# family[0] # throws an error (there is no ordering)\n", + "family['dad'] # returns 'homer'\n", + "len(family) # returns 3\n", + "family.keys() # returns list: ['dad', 'mom', 'size']\n", + "family.values() # returns list: ['homer', 'marge', 6]\n", + "family.items() # returns list of tuples:\n", + " # [('dad', 'homer'), ('mom', 'marge'), ('size', 6)]\n", + "\n", + "# modify a dictionary\n", + "family['cat'] = 'snowball' # add a new entry\n", + "family['cat'] = 'snowball ii' # edit an existing entry\n", + "del family['cat'] # delete an entry\n", + "family['kids'] = ['bart', 'lisa'] # value can be a list\n", + "\n", + "# accessing a list element within a dictionary\n", + "family['kids'][0] # returns 'bart'\n", + "\n", + "# EXERCISE:\n", + "# Given that: d = {'a':10, 'b':20, 'c':[30, 40]}\n", + "\n", + "# First, print the value for 'a'\n", + "\n", + "# Then, change the value for 'b' to be 25\n", + "\n", + "# Then, change the 30 to be 35\n", + "\n", + "# Finally, append 45 to the end of the list that contains 35 and 40\n" + ] } ], "metadata": { diff --git a/class_one/06_dicts.py b/class_one/06_dicts.py deleted file mode 100644 index 6401b4e..0000000 --- a/class_one/06_dicts.py +++ /dev/null @@ -1,47 +0,0 @@ -## DICTIONARIES - -# dictionaries are similar to lists: -# - both can contain multiple data types -# - both are iterable -# - both are mutable - -# dictionaries are different from lists: -# - dictionaries are unordered* -# - dictionary lookup time is constant regardless of dictionary size - -# dictionaries are like real dictionaries: -# - dictionaries are made of key-value pairs (word and definition) -# - dictionary keys must be unique (each word is only defined once) -# - you can use the key to look up the value, but not the other way around - -# create a dictionary (and open Variable Explorer in Spyder) -family = {'dad':'homer', 'mom':'marge', 'size':6} - -# examine a dictionary -# family[0] # throws an error (there is no ordering) -family['dad'] # returns 'homer' -len(family) # returns 3 -family.keys() # returns list: ['dad', 'mom', 'size'] -family.values() # returns list: ['homer', 'marge', 6] -family.items() # returns list of tuples: - # [('dad', 'homer'), ('mom', 'marge'), ('size', 6)] - -# modify a dictionary -family['cat'] = 'snowball' # add a new entry -family['cat'] = 'snowball ii' # edit an existing entry -del family['cat'] # delete an entry -family['kids'] = ['bart', 'lisa'] # value can be a list - -# accessing a list element within a dictionary -family['kids'][0] # returns 'bart' - -# EXERCISE: -# Given that: d = {'a':10, 'b':20, 'c':[30, 40]} - -# First, print the value for 'a' - -# Then, change the value for 'b' to be 25 - -# Then, change the 30 to be 35 - -# Finally, append 45 to the end of the list that contains 35 and 40