├── 00-Python Object and Data Structure Basics ├── .ipynb_checkpoints │ ├── 01-Variable Assignment-checkpoint.ipynb │ ├── 02-Strings-checkpoint.ipynb │ ├── 03-Print Formatting with Strings-checkpoint.ipynb │ ├── 07-Sets and Booleans-checkpoint.ipynb │ ├── 08-Files-checkpoint.ipynb │ ├── 09-Objects and Data Structures Assessment Test-checkpoint.ipynb │ └── 10-Objects and Data Structures Assessment Test-Solution-checkpoint.ipynb ├── 01-Numbers.ipynb ├── 01-Variable Assignment.ipynb ├── 02-Strings.ipynb ├── 03-Print Formatting with Strings.ipynb ├── 04-Lists.ipynb ├── 05-Dictionaries.ipynb ├── 06-Tuples.ipynb ├── 07-Sets and Booleans.ipynb ├── 08-Files.ipynb ├── 09-Objects and Data Structures Assessment Test.ipynb ├── 10-Objects and Data Structures Assessment Test-Solution.ipynb └── test.txt ├── 01-Python Comparison Operators ├── .ipynb_checkpoints │ ├── 01-Comparison Operators-checkpoint.ipynb │ └── 02-Chained Comparison Operators-checkpoint.ipynb ├── 01-Comparison Operators.ipynb └── 02-Chained Comparison Operators.ipynb ├── 02-Python Statements ├── .ipynb_checkpoints │ ├── 01-Introduction to Python Statements-checkpoint.ipynb │ ├── 02-if, elif, and else Statements-checkpoint.ipynb │ ├── 03-for Loops-checkpoint.ipynb │ ├── 04-while Loops-checkpoint.ipynb │ ├── 05-Useful-Operators-checkpoint.ipynb │ ├── 05-range()-checkpoint.ipynb │ ├── 06-List Comprehensions-checkpoint.ipynb │ ├── 07-Statements Assessment Test-checkpoint.ipynb │ ├── 08-Statements Assessment Test - Solutions-checkpoint.ipynb │ ├── 09-Guessing Game Challenge-checkpoint.ipynb │ └── 10-Guessing Game Challenge - Solution-checkpoint.ipynb ├── 01-Introduction to Python Statements.ipynb ├── 02-if, elif, and else Statements.ipynb ├── 03-for Loops.ipynb ├── 04-while Loops.ipynb ├── 05-Useful-Operators.ipynb ├── 06-List Comprehensions.ipynb ├── 07-Statements Assessment Test.ipynb ├── 08-Statements Assessment Test - Solutions.ipynb ├── 09-Guessing Game Challenge.ipynb └── 10-Guessing Game Challenge - Solution.ipynb ├── 03-Methods and Functions ├── .ipynb_checkpoints │ ├── 01-Methods-checkpoint.ipynb │ ├── 02-Functions-checkpoint.ipynb │ ├── 03-Function Practice Exercises-checkpoint.ipynb │ ├── 03-Lambda expressions-checkpoint.ipynb │ ├── 04-Function Practice Exercises - Solutions-checkpoint.ipynb │ ├── 04-Nested Statements and Scope-checkpoint.ipynb │ ├── 05-Functions and Methods Homework-checkpoint.ipynb │ ├── 05-Lambda-Expressions-Map-and-Filter-checkpoint.ipynb │ ├── 06-Functions and Methods Homework - Solutions-checkpoint.ipynb │ ├── 07-args and kwargs-checkpoint.ipynb │ ├── 08-Function Practice Exercises-checkpoint.ipynb │ └── 09-Function Practice Exercises - Solutions-checkpoint.ipynb ├── 01-Methods.ipynb ├── 02-Functions.ipynb ├── 03-Function Practice Exercises.ipynb ├── 04-Function Practice Exercises - Solutions.ipynb ├── 05-Lambda-Expressions-Map-and-Filter.ipynb ├── 06-Nested Statements and Scope.ipynb ├── 07-args and kwargs.ipynb ├── 08-Functions and Methods Homework.ipynb └── 09-Functions and Methods Homework - Solutions.ipynb ├── 04-Milestone Project - 1 ├── .ipynb_checkpoints │ ├── 01-Milestone Project 1 - Assignment-checkpoint.ipynb │ ├── 02-Milestone Project 1 - Walkthrough Steps Workbook-checkpoint.ipynb │ ├── 03-Milestone Project 1 - Complete Walkthrough Solution-checkpoint.ipynb │ └── 04-OPTIONAL -Milestone Project 1 - Advanced Solution-checkpoint.ipynb ├── 01-Milestone Project 1 - Assignment.ipynb ├── 02-Milestone Project 1 - Walkthrough Steps Workbook.ipynb ├── 03-Milestone Project 1 - Complete Walkthrough Solution.ipynb └── 04-OPTIONAL -Milestone Project 1 - Advanced Solution.ipynb ├── 05-Object Oriented Programming ├── .ipynb_checkpoints │ ├── 01-Object Oriented Programming-Copy1-checkpoint.ipynb │ ├── 01-Object Oriented Programming-checkpoint.ipynb │ ├── 02-Object Oriented Programming Homework-checkpoint.ipynb │ ├── 03-Object Oriented Programming Homework - Solution-checkpoint.ipynb │ ├── 04-OOP Challenge-checkpoint.ipynb │ └── 05-OOP Challenge - Solution-checkpoint.ipynb ├── 01-Object Oriented Programming.ipynb ├── 02-Object Oriented Programming Homework.ipynb ├── 03-Object Oriented Programming Homework - Solution.ipynb ├── 04-OOP Challenge.ipynb └── 05-OOP Challenge - Solution.ipynb ├── 06-Modules and Packages ├── .ipynb_checkpoints │ ├── 01-Modules and Packages-checkpoint.ipynb │ └── Useful_Info_Notebook-checkpoint.ipynb ├── 00-Modules_and_Packages │ ├── MyMainPackage │ │ ├── SubPackage │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ └── mysubscript.cpython-36.pyc │ │ │ └── mysubscript.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-36.pyc │ │ │ └── some_main_script.cpython-36.pyc │ │ └── some_main_script.py │ ├── mymodule.py │ └── myprogram.py ├── 01-Name_and_Main │ ├── Explanation.txt │ ├── one.py │ └── two.py ├── Useful_Info_Notebook.ipynb ├── __pycache__ │ └── file1.cpython-36.pyc ├── file1.py ├── file2.py └── file3.py ├── 07-Errors and Exception Handling ├── .ipynb_checkpoints │ ├── 01-Errors and Exceptions Handling-checkpoint.ipynb │ ├── 02-Errors and Exceptions Homework-checkpoint.ipynb │ ├── 03-Errors and Exceptions Homework - Solution-checkpoint.ipynb │ └── 04-Unit Testing-checkpoint.ipynb ├── 01-Errors and Exceptions Handling.ipynb ├── 02-Errors and Exceptions Homework.ipynb ├── 03-Errors and Exceptions Homework - Solution.ipynb ├── 04-Unit Testing.ipynb ├── __pycache__ │ └── cap.cpython-36.pyc ├── cap.py ├── simple1.py ├── simple2.py ├── test_cap.py └── testfile ├── 08-Milestone Project - 2 ├── .ipynb_checkpoints │ ├── 01-Milestone Project 2 - Assignment-checkpoint.ipynb │ ├── 02-Milestone Project 2 - Walkthrough Steps Workbook-checkpoint.ipynb │ ├── 03-Milestone Project 2 - Complete Walkthrough Solution-checkpoint.ipynb │ └── 04-Milestone Project 2 - Solution Code-checkpoint.ipynb ├── 01-Milestone Project 2 - Assignment.ipynb ├── 02-Milestone Project 2 - Walkthrough Steps Workbook.ipynb ├── 03-Milestone Project 2 - Complete Walkthrough Solution.ipynb └── 04-Milestone Project 2 - Solution Code.ipynb ├── 09-Built-in Functions ├── .ipynb_checkpoints │ ├── 01-Map-checkpoint.ipynb │ ├── 02-Reduce-checkpoint.ipynb │ ├── 03-Filter-checkpoint.ipynb │ ├── 04-Zip-checkpoint.ipynb │ ├── 05-Enumerate-checkpoint.ipynb │ ├── 06-all() and any()-checkpoint.ipynb │ ├── 07-Complex-checkpoint.ipynb │ ├── 08-Built-in Functions Assessment Test-checkpoint.ipynb │ └── 09-Built-in Functions Assessment Test - Solution-checkpoint.ipynb ├── 01-Map.ipynb ├── 02-Reduce.ipynb ├── 03-Filter.ipynb ├── 04-Zip.ipynb ├── 05-Enumerate.ipynb ├── 06-all() and any().ipynb ├── 07-Complex.ipynb ├── 08-Built-in Functions Assessment Test.ipynb └── 09-Built-in Functions Assessment Test - Solution.ipynb ├── 10-Python Decorators ├── .ipynb_checkpoints │ ├── 01-Decorators-checkpoint.ipynb │ └── 02-Decorators Homework-checkpoint.ipynb ├── 01-Decorators.ipynb └── 02-Decorators Homework.ipynb ├── 11-Python Generators ├── .ipynb_checkpoints │ ├── 01-Iterators and Generators-checkpoint.ipynb │ ├── 02-Iterators and Generators Homework-checkpoint.ipynb │ └── 03-Iterators and Generators Homework - Solution-checkpoint.ipynb ├── 01-Iterators and Generators.ipynb ├── 02-Iterators and Generators Homework.ipynb └── 03-Iterators and Generators Homework - Solution.ipynb ├── 12-Final Capstone Python Project ├── .ipynb_checkpoints │ ├── 01-Final Capstone Project-checkpoint.ipynb │ ├── 02-Final Capstone Project Ideas-checkpoint.ipynb │ └── 03-Final Capstone Suggested Walkthrough-checkpoint.ipynb ├── 01-Final Capstone Project.ipynb ├── 02-Final Capstone Project Ideas.ipynb ├── 03-Final Capstone Suggested Walkthrough.ipynb └── Projects-Solutions │ └── Solution Links.md ├── 13-Advanced Python Modules ├── .ipynb_checkpoints │ ├── 01-Collections Module-checkpoint.ipynb │ ├── 02-Datetime-checkpoint.ipynb │ ├── 03-Python Debugger (pdb)-checkpoint.ipynb │ ├── 04-Timing your code - timeit-checkpoint.ipynb │ ├── 05-Regular Expressions - re-checkpoint.ipynb │ └── 06-StringIO-checkpoint.ipynb ├── 01-Collections Module.ipynb ├── 02-Datetime.ipynb ├── 03-Python Debugger (pdb).ipynb ├── 04-Timing your code - timeit.ipynb ├── 05-Regular Expressions - re.ipynb └── 06-StringIO.ipynb ├── 14-Advanced Python Objects and Data Structures ├── .ipynb_checkpoints │ ├── 01-Advanced Numbers-checkpoint.ipynb │ ├── 02-Advanced Strings-checkpoint.ipynb │ ├── 03-Advanced Sets-checkpoint.ipynb │ ├── 04-Advanced Dictionaries-checkpoint.ipynb │ ├── 05-Advanced Lists-checkpoint.ipynb │ ├── 06-Advanced Python Objects Test-checkpoint.ipynb │ └── 07-Advanced Python Objects Test - Solutions-checkpoint.ipynb ├── 01-Advanced Numbers.ipynb ├── 02-Advanced Strings.ipynb ├── 03-Advanced Sets.ipynb ├── 04-Advanced Dictionaries.ipynb ├── 05-Advanced Lists.ipynb ├── 06-Advanced Python Objects Test.ipynb ├── 07-Advanced Python Objects Test - Solutions.ipynb └── 08-BONUS - With Statement Context Managers.ipynb ├── 15-Advanced OOP ├── .ipynb_checkpoints │ └── 01-Advanced Object Oriented Programming-checkpoint.ipynb └── 01-Advanced Object Oriented Programming.ipynb ├── 16-Bonus Material - Introduction to GUIs ├── .ipynb_checkpoints │ ├── 01-Interact-checkpoint.ipynb │ ├── 02-Widget Basics-checkpoint.ipynb │ ├── 03-Widget List-checkpoint.ipynb │ ├── 04-Widget Events-checkpoint.ipynb │ ├── 05-Widget Styling-checkpoint.ipynb │ ├── 06-Custom Widget-checkpoint.ipynb │ ├── 07-Advanced Widget List-checkpoint.ipynb │ └── 08-Advanced Widget Styling with Layout-checkpoint.ipynb ├── 01-Interact.ipynb ├── 02-Widget Basics.ipynb ├── 03-Widget List.ipynb ├── 04-Widget Events.ipynb ├── 05-Widget Styling.ipynb ├── 06-Custom Widget.ipynb ├── 07-Advanced Widget List.ipynb └── 08-Advanced Widget Styling with Layout.ipynb ├── 17-Parallel Processing ├── .ipynb_checkpoints │ └── 01-Multithreading and Multiprocessing-checkpoint.ipynb ├── 01-Multithreading and Multiprocessing.ipynb ├── test.py └── test2.py ├── FAQ.ipynb ├── Jupyter (iPython) Notebooks Guide.ipynb └── README.md /00-Python Object and Data Structure Basics/test.txt: -------------------------------------------------------------------------------- 1 | First Line 2 | Second Line -------------------------------------------------------------------------------- /01-Python Comparison Operators/.ipynb_checkpoints/02-Chained Comparison Operators-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Chained Comparison Operators\n", 8 | "\n", 9 | "An interesting feature of Python is the ability to *chain* multiple comparisons to perform a more complex test. You can use these chained comparisons as shorthand for larger Boolean Expressions.\n", 10 | "\n", 11 | "In this lecture we will learn how to chain comparison operators and we will also introduce two other important statements in Python: **and** and **or**.\n", 12 | "\n", 13 | "Let's look at a few examples of using chains:" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 1, 19 | "metadata": {}, 20 | "outputs": [ 21 | { 22 | "data": { 23 | "text/plain": [ 24 | "True" 25 | ] 26 | }, 27 | "execution_count": 1, 28 | "metadata": {}, 29 | "output_type": "execute_result" 30 | } 31 | ], 32 | "source": [ 33 | "1 < 2 < 3" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "The above statement checks if 1 was less than 2 **and** if 2 was less than 3. We could have written this using an **and** statement in Python:" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 2, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "True" 52 | ] 53 | }, 54 | "execution_count": 2, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "1<2 and 2<3" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "The **and** is used to make sure two checks have to be true in order for the total check to be true. Let's see another example:" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 3, 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "True" 79 | ] 80 | }, 81 | "execution_count": 3, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "1 < 3 > 2" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "The above checks if 3 is larger than both of the other numbers, so you could use **and** to rewrite it as:" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "True" 106 | ] 107 | }, 108 | "execution_count": 4, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "1<3 and 3>2" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "It's important to note that Python is checking both instances of the comparisons. We can also use **or** to write comparisons in Python. For example:" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 5, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "data": { 131 | "text/plain": [ 132 | "True" 133 | ] 134 | }, 135 | "execution_count": 5, 136 | "metadata": {}, 137 | "output_type": "execute_result" 138 | } 139 | ], 140 | "source": [ 141 | "1==2 or 2<3" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": {}, 147 | "source": [ 148 | "Note how it was true; this is because with the **or** operator, we only need one *or* the other to be true. Let's see one more example to drive this home:" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 6, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "data": { 158 | "text/plain": [ 159 | "True" 160 | ] 161 | }, 162 | "execution_count": 6, 163 | "metadata": {}, 164 | "output_type": "execute_result" 165 | } 166 | ], 167 | "source": [ 168 | "1==1 or 100==1" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": {}, 174 | "source": [ 175 | "Great! For an overview of this quick lesson: You should have a comfortable understanding of using **and** and **or** statements as well as reading chained comparison code.\n", 176 | "\n", 177 | "Go ahead and go to the quiz for this section to check your understanding!" 178 | ] 179 | } 180 | ], 181 | "metadata": { 182 | "kernelspec": { 183 | "display_name": "Python 3", 184 | "language": "python", 185 | "name": "python3" 186 | }, 187 | "language_info": { 188 | "codemirror_mode": { 189 | "name": "ipython", 190 | "version": 3 191 | }, 192 | "file_extension": ".py", 193 | "mimetype": "text/x-python", 194 | "name": "python", 195 | "nbconvert_exporter": "python", 196 | "pygments_lexer": "ipython3", 197 | "version": "3.6.2" 198 | } 199 | }, 200 | "nbformat": 4, 201 | "nbformat_minor": 1 202 | } 203 | -------------------------------------------------------------------------------- /01-Python Comparison Operators/02-Chained Comparison Operators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Chained Comparison Operators\n", 8 | "\n", 9 | "An interesting feature of Python is the ability to *chain* multiple comparisons to perform a more complex test. You can use these chained comparisons as shorthand for larger Boolean Expressions.\n", 10 | "\n", 11 | "In this lecture we will learn how to chain comparison operators and we will also introduce two other important statements in Python: **and** and **or**.\n", 12 | "\n", 13 | "Let's look at a few examples of using chains:" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 1, 19 | "metadata": {}, 20 | "outputs": [ 21 | { 22 | "data": { 23 | "text/plain": [ 24 | "True" 25 | ] 26 | }, 27 | "execution_count": 1, 28 | "metadata": {}, 29 | "output_type": "execute_result" 30 | } 31 | ], 32 | "source": [ 33 | "1 < 2 < 3" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "The above statement checks if 1 was less than 2 **and** if 2 was less than 3. We could have written this using an **and** statement in Python:" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 2, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "True" 52 | ] 53 | }, 54 | "execution_count": 2, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "1<2 and 2<3" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "The **and** is used to make sure two checks have to be true in order for the total check to be true. Let's see another example:" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 3, 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "True" 79 | ] 80 | }, 81 | "execution_count": 3, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "1 < 3 > 2" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "The above checks if 3 is larger than both of the other numbers, so you could use **and** to rewrite it as:" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "True" 106 | ] 107 | }, 108 | "execution_count": 4, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "1<3 and 3>2" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "It's important to note that Python is checking both instances of the comparisons. We can also use **or** to write comparisons in Python. For example:" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 5, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "data": { 131 | "text/plain": [ 132 | "True" 133 | ] 134 | }, 135 | "execution_count": 5, 136 | "metadata": {}, 137 | "output_type": "execute_result" 138 | } 139 | ], 140 | "source": [ 141 | "1==2 or 2<3" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": {}, 147 | "source": [ 148 | "Note how it was true; this is because with the **or** operator, we only need one *or* the other to be true. Let's see one more example to drive this home:" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 6, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "data": { 158 | "text/plain": [ 159 | "True" 160 | ] 161 | }, 162 | "execution_count": 6, 163 | "metadata": {}, 164 | "output_type": "execute_result" 165 | } 166 | ], 167 | "source": [ 168 | "1==1 or 100==1" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": {}, 174 | "source": [ 175 | "Great! For an overview of this quick lesson: You should have a comfortable understanding of using **and** and **or** statements as well as reading chained comparison code.\n", 176 | "\n", 177 | "Go ahead and go to the quiz for this section to check your understanding!" 178 | ] 179 | } 180 | ], 181 | "metadata": { 182 | "kernelspec": { 183 | "display_name": "Python 3", 184 | "language": "python", 185 | "name": "python3" 186 | }, 187 | "language_info": { 188 | "codemirror_mode": { 189 | "name": "ipython", 190 | "version": 3 191 | }, 192 | "file_extension": ".py", 193 | "mimetype": "text/x-python", 194 | "name": "python", 195 | "nbconvert_exporter": "python", 196 | "pygments_lexer": "ipython3", 197 | "version": "3.6.2" 198 | } 199 | }, 200 | "nbformat": 4, 201 | "nbformat_minor": 1 202 | } 203 | -------------------------------------------------------------------------------- /02-Python Statements/.ipynb_checkpoints/01-Introduction to Python Statements-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Introduction to Python Statements\n", 12 | "\n", 13 | "In this lecture we will be doing a quick overview of Python Statements. This lecture will emphasize differences between Python and other languages such as C++. \n", 14 | "\n", 15 | "There are two reasons we take this approach for learning the context of Python Statements:\n", 16 | "\n", 17 | " 1.) If you are coming from a different language this will rapidly accelerate your understanding of Python.\n", 18 | " 2.) Learning about statements will allow you to be able to read other languages more easily in the future." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "slideshow": { 25 | "slide_type": "slide" 26 | } 27 | }, 28 | "source": [ 29 | "## Python vs Other Languages\n", 30 | "\n", 31 | "Let's create a simple statement that says:\n", 32 | "\"If a is greater than b, assign 2 to a and 4 to b\"\n", 33 | "\n", 34 | "Take a look at these two if statements (we will learn about building out if statements soon).\n", 35 | "\n", 36 | "**Version 1 (Other Languages)**\n", 37 | "\n", 38 | " if (a>b){\n", 39 | " a = 2;\n", 40 | " b = 4;\n", 41 | " }\n", 42 | " \n", 43 | "**Version 2 (Python)** \n", 44 | "\n", 45 | " if a>b:\n", 46 | " a = 2\n", 47 | " b = 4" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "You'll notice that Python is less cluttered and much more readable than the first version. How does Python manage this?\n", 55 | "\n", 56 | "Let's walk through the main differences:\n", 57 | "\n", 58 | "Python gets rid of () and {} by incorporating two main factors: a *colon* and *whitespace*. The statement is ended with a colon, and whitespace is used (indentation) to describe what takes place in case of the statement.\n", 59 | "\n", 60 | "Another major difference is the lack of semicolons in Python. Semicolons are used to denote statement endings in many other languages, but in Python, the end of a line is the same as the end of a statement.\n", 61 | "\n", 62 | "Lastly, to end this brief overview of differences, let's take a closer look at indentation syntax in Python vs other languages:\n", 63 | "\n", 64 | "## Indentation\n", 65 | "\n", 66 | "Here is some pseudo-code to indicate the use of whitespace and indentation in Python:\n", 67 | "\n", 68 | "**Other Languages**\n", 69 | "\n", 70 | " if (x)\n", 71 | " if(y)\n", 72 | " code-statement;\n", 73 | " else\n", 74 | " another-code-statement;\n", 75 | " \n", 76 | "**Python**\n", 77 | " \n", 78 | " if x:\n", 79 | " if y:\n", 80 | " code-statement\n", 81 | " else:\n", 82 | " another-code-statement" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "Note how Python is so heavily driven by code indentation and whitespace. This means that code readability is a core part of the design of the Python language.\n", 90 | "\n", 91 | "Now let's start diving deeper by coding these sort of statements in Python!" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": { 97 | "collapsed": true 98 | }, 99 | "source": [ 100 | "## Time to code!" 101 | ] 102 | } 103 | ], 104 | "metadata": { 105 | "kernelspec": { 106 | "display_name": "Python 3", 107 | "language": "python", 108 | "name": "python3" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": { 112 | "name": "ipython", 113 | "version": 3 114 | }, 115 | "file_extension": ".py", 116 | "mimetype": "text/x-python", 117 | "name": "python", 118 | "nbconvert_exporter": "python", 119 | "pygments_lexer": "ipython3", 120 | "version": "3.6.2" 121 | } 122 | }, 123 | "nbformat": 4, 124 | "nbformat_minor": 1 125 | } 126 | -------------------------------------------------------------------------------- /02-Python Statements/.ipynb_checkpoints/05-range()-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# range()\n", 8 | "\n", 9 | "In this short lecture we will be discussing the range function. We haven't developed a very deep level of knowledge of functions yet, but we can understand the basics of this simple (but extremely useful!) function.\n", 10 | "\n", 11 | "range() allows us to generate a list of numbers ranging from a starting point *up to but not including* an ending point. We can also specify step size. Let's walk through a few examples:" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "data": { 21 | "text/plain": [ 22 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" 23 | ] 24 | }, 25 | "execution_count": 1, 26 | "metadata": {}, 27 | "output_type": "execute_result" 28 | } 29 | ], 30 | "source": [ 31 | "list(range(0,10))" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "To see the output of range() as a list, we *cast* it as a list as shown above. This is rarely done, as normally range is used in for loops." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 6, 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "data": { 48 | "text/plain": [ 49 | "range" 50 | ] 51 | }, 52 | "execution_count": 6, 53 | "metadata": {}, 54 | "output_type": "execute_result" 55 | } 56 | ], 57 | "source": [ 58 | "# Range objects\n", 59 | "x =range(0,10)\n", 60 | "type(x)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "range objects behave like *generators* - they don't produce every value all at once, but deliver them one at a time as needed. Behind the scenes this saves on overhead since you're not storing every value, and it improves the performance of your code! We will learn more about generators later on in the course." 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 3, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "start = 0 #Default\n", 77 | "stop = 20 \n", 78 | "x = range(start,stop)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 4, 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "data": { 88 | "text/plain": [ 89 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]" 90 | ] 91 | }, 92 | "execution_count": 4, 93 | "metadata": {}, 94 | "output_type": "execute_result" 95 | } 96 | ], 97 | "source": [ 98 | "list(x)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "Great! Notice how it went *up to* 20, but doesn't actually produce 20. Just like in indexing. What about step size? We can specify that as a third argument:" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 5, 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "data": { 115 | "text/plain": [ 116 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" 117 | ] 118 | }, 119 | "execution_count": 5, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "x = range(start,stop,2)\n", 126 | "\n", 127 | "#Show\n", 128 | "list(x)" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": { 134 | "collapsed": true 135 | }, 136 | "source": [ 137 | "You should now have a good understanding of how to use range() in Python." 138 | ] 139 | } 140 | ], 141 | "metadata": { 142 | "kernelspec": { 143 | "display_name": "Python 3", 144 | "language": "python", 145 | "name": "python3" 146 | }, 147 | "language_info": { 148 | "codemirror_mode": { 149 | "name": "ipython", 150 | "version": 3 151 | }, 152 | "file_extension": ".py", 153 | "mimetype": "text/x-python", 154 | "name": "python", 155 | "nbconvert_exporter": "python", 156 | "pygments_lexer": "ipython3", 157 | "version": "3.6.2" 158 | } 159 | }, 160 | "nbformat": 4, 161 | "nbformat_minor": 1 162 | } 163 | -------------------------------------------------------------------------------- /02-Python Statements/.ipynb_checkpoints/07-Statements Assessment Test-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true 7 | }, 8 | "source": [ 9 | "# Statements Assessment Test\n", 10 | "Let's test your knowledge!" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "_____\n", 18 | "**Use for, .split(), and if to create a Statement that will print out words that start with 's':**" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 3, 24 | "metadata": { 25 | "collapsed": true 26 | }, 27 | "outputs": [], 28 | "source": [ 29 | "st = 'Print only the words that start with s in this sentence'" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 1, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "#Code here" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "______\n", 46 | "**Use range() to print all the even numbers from 0 to 10.**" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 2, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "#Code Here" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "___\n", 63 | "**Use a List Comprehension to create a list of all numbers between 1 and 50 that are divisible by 3.**" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "[]" 75 | ] 76 | }, 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "#Code in this cell\n", 84 | "[]" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "_____\n", 92 | "**Go through the string below and if the length of a word is even print \"even!\"**" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 6, 98 | "metadata": { 99 | "collapsed": true 100 | }, 101 | "outputs": [], 102 | "source": [ 103 | "st = 'Print every word in this sentence that has an even number of letters'" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 4, 109 | "metadata": { 110 | "collapsed": true 111 | }, 112 | "outputs": [], 113 | "source": [ 114 | "#Code in this cell" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "____\n", 122 | "**Write a program that prints the integers from 1 to 100. But for multiples of three print \"Fizz\" instead of the number, and for the multiples of five print \"Buzz\". For numbers which are multiples of both three and five print \"FizzBuzz\".**" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "#Code in this cell" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "____\n", 139 | "**Use List Comprehension to create a list of the first letters of every word in the string below:**" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 8, 145 | "metadata": { 146 | "collapsed": true 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "st = 'Create a list of the first letters of every word in this string'" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 5, 156 | "metadata": { 157 | "collapsed": true 158 | }, 159 | "outputs": [], 160 | "source": [ 161 | "#Code in this cell" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "### Great Job!" 169 | ] 170 | } 171 | ], 172 | "metadata": { 173 | "kernelspec": { 174 | "display_name": "Python 3", 175 | "language": "python", 176 | "name": "python3" 177 | }, 178 | "language_info": { 179 | "codemirror_mode": { 180 | "name": "ipython", 181 | "version": 3 182 | }, 183 | "file_extension": ".py", 184 | "mimetype": "text/x-python", 185 | "name": "python", 186 | "nbconvert_exporter": "python", 187 | "pygments_lexer": "ipython3", 188 | "version": "3.6.2" 189 | } 190 | }, 191 | "nbformat": 4, 192 | "nbformat_minor": 1 193 | } 194 | -------------------------------------------------------------------------------- /02-Python Statements/.ipynb_checkpoints/09-Guessing Game Challenge-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Guessing Game Challenge\n", 8 | "\n", 9 | "Let's use `while` loops to create a guessing game.\n", 10 | "\n", 11 | "The Challenge:\n", 12 | "\n", 13 | "Write a program that picks a random integer from 1 to 100, and has players guess the number. The rules are:\n", 14 | "\n", 15 | "1. If a player's guess is less than 1 or greater than 100, say \"OUT OF BOUNDS\"\n", 16 | "2. On a player's first turn, if their guess is\n", 17 | " * within 10 of the number, return \"WARM!\"\n", 18 | " * further than 10 away from the number, return \"COLD!\"\n", 19 | "3. On all subsequent turns, if a guess is \n", 20 | " * closer to the number than the previous guess return \"WARMER!\"\n", 21 | " * farther from the number than the previous guess, return \"COLDER!\"\n", 22 | "4. When the player's guess equals the number, tell them they've guessed correctly *and* how many guesses it took!\n", 23 | "\n", 24 | "You can try this from scratch, or follow the steps outlined below. A separate Solution notebook has been provided. Good luck!\n" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "#### First, pick a random integer from 1 to 100 using the random module and assign it to a variable\n", 32 | "\n", 33 | "Note: `random.randint(a,b)` returns a random integer in range `[a, b]`, including both end points." 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "#### Next, print an introduction to the game and explain the rules" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "#### Create a list to store guesses\n", 62 | "\n", 63 | "Hint: zero is a good placeholder value. It's useful because it evaluates to \"False\"" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "#### Write a `while` loop that asks for a valid guess. Test it a few times to make sure it works." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "while True:\n", 87 | " \n", 88 | " pass" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "#### Write a `while` loop that compares the player's guess to our number. If the player guesses correctly, break from the loop. Otherwise, tell the player if they're warmer or colder, and continue asking for guesses.\n", 96 | "\n", 97 | "Some hints:\n", 98 | "* it may help to sketch out all possible combinations on paper first!\n", 99 | "* you can use the `abs()` function to find the positive difference between two numbers\n", 100 | "* if you append all new guesses to the list, then the previous guess is given as `guesses[-2]`" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "while True:\n", 110 | "\n", 111 | " # we can copy the code from above to take an input\n", 112 | "\n", 113 | " pass" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "That's it! You've just programmed your first game!\n", 121 | "\n", 122 | "In the next section we'll learn how to turn some of these repetitive actions into *functions* that can be called whenever we need them." 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "### Good Job!" 130 | ] 131 | } 132 | ], 133 | "metadata": { 134 | "kernelspec": { 135 | "display_name": "Python 3", 136 | "language": "python", 137 | "name": "python3" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": { 141 | "name": "ipython", 142 | "version": 3 143 | }, 144 | "file_extension": ".py", 145 | "mimetype": "text/x-python", 146 | "name": "python", 147 | "nbconvert_exporter": "python", 148 | "pygments_lexer": "ipython3", 149 | "version": "3.6.2" 150 | } 151 | }, 152 | "nbformat": 4, 153 | "nbformat_minor": 2 154 | } 155 | -------------------------------------------------------------------------------- /02-Python Statements/01-Introduction to Python Statements.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Introduction to Python Statements\n", 12 | "\n", 13 | "In this lecture we will be doing a quick overview of Python Statements. This lecture will emphasize differences between Python and other languages such as C++. \n", 14 | "\n", 15 | "There are two reasons we take this approach for learning the context of Python Statements:\n", 16 | "\n", 17 | " 1.) If you are coming from a different language this will rapidly accelerate your understanding of Python.\n", 18 | " 2.) Learning about statements will allow you to be able to read other languages more easily in the future." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "slideshow": { 25 | "slide_type": "slide" 26 | } 27 | }, 28 | "source": [ 29 | "## Python vs Other Languages\n", 30 | "\n", 31 | "Let's create a simple statement that says:\n", 32 | "\"If a is greater than b, assign 2 to a and 4 to b\"\n", 33 | "\n", 34 | "Take a look at these two if statements (we will learn about building out if statements soon).\n", 35 | "\n", 36 | "**Version 1 (Other Languages)**\n", 37 | "\n", 38 | " if (a>b){\n", 39 | " a = 2;\n", 40 | " b = 4;\n", 41 | " }\n", 42 | " \n", 43 | "**Version 2 (Python)** \n", 44 | "\n", 45 | " if a>b:\n", 46 | " a = 2\n", 47 | " b = 4" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "You'll notice that Python is less cluttered and much more readable than the first version. How does Python manage this?\n", 55 | "\n", 56 | "Let's walk through the main differences:\n", 57 | "\n", 58 | "Python gets rid of () and {} by incorporating two main factors: a *colon* and *whitespace*. The statement is ended with a colon, and whitespace is used (indentation) to describe what takes place in case of the statement.\n", 59 | "\n", 60 | "Another major difference is the lack of semicolons in Python. Semicolons are used to denote statement endings in many other languages, but in Python, the end of a line is the same as the end of a statement.\n", 61 | "\n", 62 | "Lastly, to end this brief overview of differences, let's take a closer look at indentation syntax in Python vs other languages:\n", 63 | "\n", 64 | "## Indentation\n", 65 | "\n", 66 | "Here is some pseudo-code to indicate the use of whitespace and indentation in Python:\n", 67 | "\n", 68 | "**Other Languages**\n", 69 | "\n", 70 | " if (x)\n", 71 | " if(y)\n", 72 | " code-statement;\n", 73 | " else\n", 74 | " another-code-statement;\n", 75 | " \n", 76 | "**Python**\n", 77 | " \n", 78 | " if x:\n", 79 | " if y:\n", 80 | " code-statement\n", 81 | " else:\n", 82 | " another-code-statement" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "Note how Python is so heavily driven by code indentation and whitespace. This means that code readability is a core part of the design of the Python language.\n", 90 | "\n", 91 | "Now let's start diving deeper by coding these sort of statements in Python!" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": { 97 | "collapsed": true 98 | }, 99 | "source": [ 100 | "## Time to code!" 101 | ] 102 | } 103 | ], 104 | "metadata": { 105 | "kernelspec": { 106 | "display_name": "Python 3", 107 | "language": "python", 108 | "name": "python3" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": { 112 | "name": "ipython", 113 | "version": 3 114 | }, 115 | "file_extension": ".py", 116 | "mimetype": "text/x-python", 117 | "name": "python", 118 | "nbconvert_exporter": "python", 119 | "pygments_lexer": "ipython3", 120 | "version": "3.6.2" 121 | } 122 | }, 123 | "nbformat": 4, 124 | "nbformat_minor": 1 125 | } 126 | -------------------------------------------------------------------------------- /02-Python Statements/07-Statements Assessment Test.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true 7 | }, 8 | "source": [ 9 | "# Statements Assessment Test\n", 10 | "Let's test your knowledge!" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "_____\n", 18 | "**Use for, .split(), and if to create a Statement that will print out words that start with 's':**" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "st = 'Print only the words that start with s in this sentence'" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "#Code here" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "______\n", 44 | "**Use range() to print all the even numbers from 0 to 10.**" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "#Code Here" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "___\n", 61 | "**Use a List Comprehension to create a list of all numbers between 1 and 50 that are divisible by 3.**" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "#Code in this cell\n", 71 | "[]" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "_____\n", 79 | "**Go through the string below and if the length of a word is even print \"even!\"**" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "st = 'Print every word in this sentence that has an even number of letters'" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "#Code in this cell" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "____\n", 105 | "**Write a program that prints the integers from 1 to 100. But for multiples of three print \"Fizz\" instead of the number, and for the multiples of five print \"Buzz\". For numbers which are multiples of both three and five print \"FizzBuzz\".**" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "#Code in this cell" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "____\n", 122 | "**Use List Comprehension to create a list of the first letters of every word in the string below:**" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "st = 'Create a list of the first letters of every word in this string'" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "#Code in this cell" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "### Great Job!" 148 | ] 149 | } 150 | ], 151 | "metadata": { 152 | "kernelspec": { 153 | "display_name": "Python 3", 154 | "language": "python", 155 | "name": "python3" 156 | }, 157 | "language_info": { 158 | "codemirror_mode": { 159 | "name": "ipython", 160 | "version": 3 161 | }, 162 | "file_extension": ".py", 163 | "mimetype": "text/x-python", 164 | "name": "python", 165 | "nbconvert_exporter": "python", 166 | "pygments_lexer": "ipython3", 167 | "version": "3.6.2" 168 | } 169 | }, 170 | "nbformat": 4, 171 | "nbformat_minor": 1 172 | } 173 | -------------------------------------------------------------------------------- /02-Python Statements/09-Guessing Game Challenge.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Guessing Game Challenge\n", 8 | "\n", 9 | "Let's use `while` loops to create a guessing game.\n", 10 | "\n", 11 | "The Challenge:\n", 12 | "\n", 13 | "Write a program that picks a random integer from 1 to 100, and has players guess the number. The rules are:\n", 14 | "\n", 15 | "1. If a player's guess is less than 1 or greater than 100, say \"OUT OF BOUNDS\"\n", 16 | "2. On a player's first turn, if their guess is\n", 17 | " * within 10 of the number, return \"WARM!\"\n", 18 | " * further than 10 away from the number, return \"COLD!\"\n", 19 | "3. On all subsequent turns, if a guess is \n", 20 | " * closer to the number than the previous guess return \"WARMER!\"\n", 21 | " * farther from the number than the previous guess, return \"COLDER!\"\n", 22 | "4. When the player's guess equals the number, tell them they've guessed correctly *and* how many guesses it took!\n", 23 | "\n", 24 | "You can try this from scratch, or follow the steps outlined below. A separate Solution notebook has been provided. Good luck!\n" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "#### First, pick a random integer from 1 to 100 using the random module and assign it to a variable\n", 32 | "\n", 33 | "Note: `random.randint(a,b)` returns a random integer in range `[a, b]`, including both end points." 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "#### Next, print an introduction to the game and explain the rules" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "#### Create a list to store guesses\n", 62 | "\n", 63 | "Hint: zero is a good placeholder value. It's useful because it evaluates to \"False\"" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "#### Write a `while` loop that asks for a valid guess. Test it a few times to make sure it works." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "while True:\n", 87 | " \n", 88 | " pass" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "#### Write a `while` loop that compares the player's guess to our number. If the player guesses correctly, break from the loop. Otherwise, tell the player if they're warmer or colder, and continue asking for guesses.\n", 96 | "\n", 97 | "Some hints:\n", 98 | "* it may help to sketch out all possible combinations on paper first!\n", 99 | "* you can use the `abs()` function to find the positive difference between two numbers\n", 100 | "* if you append all new guesses to the list, then the previous guess is given as `guesses[-2]`" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "while True:\n", 110 | "\n", 111 | " # we can copy the code from above to take an input\n", 112 | "\n", 113 | " pass" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "That's it! You've just programmed your first game!\n", 121 | "\n", 122 | "In the next section we'll learn how to turn some of these repetitive actions into *functions* that can be called whenever we need them." 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "### Good Job!" 130 | ] 131 | } 132 | ], 133 | "metadata": { 134 | "kernelspec": { 135 | "display_name": "Python 3", 136 | "language": "python", 137 | "name": "python3" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": { 141 | "name": "ipython", 142 | "version": 3 143 | }, 144 | "file_extension": ".py", 145 | "mimetype": "text/x-python", 146 | "name": "python", 147 | "nbconvert_exporter": "python", 148 | "pygments_lexer": "ipython3", 149 | "version": "3.6.2" 150 | } 151 | }, 152 | "nbformat": 4, 153 | "nbformat_minor": 2 154 | } 155 | -------------------------------------------------------------------------------- /03-Methods and Functions/.ipynb_checkpoints/01-Methods-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Methods\n", 8 | "\n", 9 | "We've already seen a few example of methods when learning about Object and Data Structure Types in Python. Methods are essentially functions built into objects. Later on in the course we will learn about how to create our own objects and methods using Object Oriented Programming (OOP) and classes.\n", 10 | "\n", 11 | "Methods perform specific actions on an object and can also take arguments, just like a function. This lecture will serve as just a brief introduction to methods and get you thinking about overall design methods that we will touch back upon when we reach OOP in the course.\n", 12 | "\n", 13 | "Methods are in the form:\n", 14 | "\n", 15 | " object.method(arg1,arg2,etc...)\n", 16 | " \n", 17 | "You'll later see that we can think of methods as having an argument 'self' referring to the object itself. You can't see this argument but we will be using it later on in the course during the OOP lectures.\n", 18 | "\n", 19 | "Let's take a quick look at what an example of the various methods a list has:" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 1, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "# Create a simple list\n", 29 | "lst = [1,2,3,4,5]" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "Fortunately, with iPython and the Jupyter Notebook we can quickly see all the possible methods using the tab key. The methods for a list are:\n", 37 | "\n", 38 | "* append\n", 39 | "* count\n", 40 | "* extend\n", 41 | "* insert\n", 42 | "* pop\n", 43 | "* remove\n", 44 | "* reverse\n", 45 | "* sort\n", 46 | "\n", 47 | "Let's try out a few of them:" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "append() allows us to add elements to the end of a list:" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 2, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "lst.append(6)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "[1, 2, 3, 4, 5, 6]" 75 | ] 76 | }, 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "lst" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "Great! Now how about count()? The count() method will count the number of occurrences of an element in a list." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 4, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "data": { 100 | "text/plain": [ 101 | "1" 102 | ] 103 | }, 104 | "execution_count": 4, 105 | "metadata": {}, 106 | "output_type": "execute_result" 107 | } 108 | ], 109 | "source": [ 110 | "# Check how many times 2 shows up in the list\n", 111 | "lst.count(2)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "You can always use Shift+Tab in the Jupyter Notebook to get more help about the method. In general Python you can use the help() function: " 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 5, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "Help on built-in function count:\n", 131 | "\n", 132 | "count(...) method of builtins.list instance\n", 133 | " L.count(value) -> integer -- return number of occurrences of value\n", 134 | "\n" 135 | ] 136 | } 137 | ], 138 | "source": [ 139 | "help(lst.count)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": {}, 145 | "source": [ 146 | "Feel free to play around with the rest of the methods for a list. Later on in this section your quiz will involve using help and Google searching for methods of different types of objects!" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "Great! By this lecture you should feel comfortable calling methods of objects in Python!" 154 | ] 155 | } 156 | ], 157 | "metadata": { 158 | "kernelspec": { 159 | "display_name": "Python 3", 160 | "language": "python", 161 | "name": "python3" 162 | }, 163 | "language_info": { 164 | "codemirror_mode": { 165 | "name": "ipython", 166 | "version": 3 167 | }, 168 | "file_extension": ".py", 169 | "mimetype": "text/x-python", 170 | "name": "python", 171 | "nbconvert_exporter": "python", 172 | "pygments_lexer": "ipython3", 173 | "version": "3.6.2" 174 | } 175 | }, 176 | "nbformat": 4, 177 | "nbformat_minor": 1 178 | } 179 | -------------------------------------------------------------------------------- /03-Methods and Functions/01-Methods.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Methods\n", 8 | "\n", 9 | "We've already seen a few example of methods when learning about Object and Data Structure Types in Python. Methods are essentially functions built into objects. Later on in the course we will learn about how to create our own objects and methods using Object Oriented Programming (OOP) and classes.\n", 10 | "\n", 11 | "Methods perform specific actions on an object and can also take arguments, just like a function. This lecture will serve as just a brief introduction to methods and get you thinking about overall design methods that we will touch back upon when we reach OOP in the course.\n", 12 | "\n", 13 | "Methods are in the form:\n", 14 | "\n", 15 | " object.method(arg1,arg2,etc...)\n", 16 | " \n", 17 | "You'll later see that we can think of methods as having an argument 'self' referring to the object itself. You can't see this argument but we will be using it later on in the course during the OOP lectures.\n", 18 | "\n", 19 | "Let's take a quick look at what an example of the various methods a list has:" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 1, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "# Create a simple list\n", 29 | "lst = [1,2,3,4,5]" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "Fortunately, with iPython and the Jupyter Notebook we can quickly see all the possible methods using the tab key. The methods for a list are:\n", 37 | "\n", 38 | "* append\n", 39 | "* count\n", 40 | "* extend\n", 41 | "* insert\n", 42 | "* pop\n", 43 | "* remove\n", 44 | "* reverse\n", 45 | "* sort\n", 46 | "\n", 47 | "Let's try out a few of them:" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "append() allows us to add elements to the end of a list:" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 2, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "lst.append(6)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "[1, 2, 3, 4, 5, 6]" 75 | ] 76 | }, 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "lst" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "Great! Now how about count()? The count() method will count the number of occurrences of an element in a list." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 4, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "data": { 100 | "text/plain": [ 101 | "1" 102 | ] 103 | }, 104 | "execution_count": 4, 105 | "metadata": {}, 106 | "output_type": "execute_result" 107 | } 108 | ], 109 | "source": [ 110 | "# Check how many times 2 shows up in the list\n", 111 | "lst.count(2)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "You can always use Shift+Tab in the Jupyter Notebook to get more help about the method. In general Python you can use the help() function: " 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 5, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "Help on built-in function count:\n", 131 | "\n", 132 | "count(...) method of builtins.list instance\n", 133 | " L.count(value) -> integer -- return number of occurrences of value\n", 134 | "\n" 135 | ] 136 | } 137 | ], 138 | "source": [ 139 | "help(lst.count)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": {}, 145 | "source": [ 146 | "Feel free to play around with the rest of the methods for a list. Later on in this section your quiz will involve using help and Google searching for methods of different types of objects!" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "Great! By this lecture you should feel comfortable calling methods of objects in Python!" 154 | ] 155 | } 156 | ], 157 | "metadata": { 158 | "kernelspec": { 159 | "display_name": "Python 3", 160 | "language": "python", 161 | "name": "python3" 162 | }, 163 | "language_info": { 164 | "codemirror_mode": { 165 | "name": "ipython", 166 | "version": 3 167 | }, 168 | "file_extension": ".py", 169 | "mimetype": "text/x-python", 170 | "name": "python", 171 | "nbconvert_exporter": "python", 172 | "pygments_lexer": "ipython3", 173 | "version": "3.6.2" 174 | } 175 | }, 176 | "nbformat": 4, 177 | "nbformat_minor": 1 178 | } 179 | -------------------------------------------------------------------------------- /04-Milestone Project - 1/.ipynb_checkpoints/01-Milestone Project 1 - Assignment-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Milestone Project 1\n", 8 | "## Congratulations on making it to your first milestone!\n", 9 | "You've already learned a ton and are ready to work on a real project.\n", 10 | "\n", 11 | "Your assignment: Create a Tic Tac Toe game. You are free to use any IDE you like.\n", 12 | "\n", 13 | "Here are the requirements:\n", 14 | "\n", 15 | "* 2 players should be able to play the game (both sitting at the same computer)\n", 16 | "* The board should be printed out every time a player makes a move\n", 17 | "* You should be able to accept input of the player position and then place a symbol on the board\n", 18 | "\n", 19 | "Feel free to use Google to help you figure anything out (but don't just Google \"Tic Tac Toe in Python\" otherwise you won't learn anything!) Keep in mind that this project can take anywhere between several hours to several days.\n", 20 | "\n", 21 | "There are 4 Jupyter Notebooks related to this assignment:\n", 22 | "\n", 23 | "* This Assignment Notebook\n", 24 | "* A \"Walkthrough Steps Workbook\" Notebook\n", 25 | "* A \"Complete Walkthrough Solution\" Notebook\n", 26 | "* An \"Advanced Solution\" Notebook\n", 27 | "\n", 28 | "I encourage you to just try to start the project on your own without referencing any of the notebooks. If you get stuck, check out the next lecture which is a text lecture with helpful hints and steps. If you're still stuck after that, then check out the Walkthrough Steps Workbook, which breaks up the project in steps for you to solve. Still stuck? Then check out the Complete Walkthrough Solution video for more help on approaching the project!" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "There are parts of this that will be a struggle...and that is good! I have complete faith that if you have made it this far through the course you have all the tools and knowledge to tackle this project. Remember, it's totally open book, so take your time, do a little research, and remember:\n", 36 | "\n", 37 | "## HAVE FUN!" 38 | ] 39 | } 40 | ], 41 | "metadata": { 42 | "kernelspec": { 43 | "display_name": "Python 3", 44 | "language": "python", 45 | "name": "python3" 46 | }, 47 | "language_info": { 48 | "codemirror_mode": { 49 | "name": "ipython", 50 | "version": 3 51 | }, 52 | "file_extension": ".py", 53 | "mimetype": "text/x-python", 54 | "name": "python", 55 | "nbconvert_exporter": "python", 56 | "pygments_lexer": "ipython3", 57 | "version": "3.6.2" 58 | } 59 | }, 60 | "nbformat": 4, 61 | "nbformat_minor": 1 62 | } 63 | -------------------------------------------------------------------------------- /04-Milestone Project - 1/01-Milestone Project 1 - Assignment.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Milestone Project 1\n", 8 | "## Congratulations on making it to your first milestone!\n", 9 | "You've already learned a ton and are ready to work on a real project.\n", 10 | "\n", 11 | "Your assignment: Create a Tic Tac Toe game. You are free to use any IDE you like.\n", 12 | "\n", 13 | "Here are the requirements:\n", 14 | "\n", 15 | "* 2 players should be able to play the game (both sitting at the same computer)\n", 16 | "* The board should be printed out every time a player makes a move\n", 17 | "* You should be able to accept input of the player position and then place a symbol on the board\n", 18 | "\n", 19 | "Feel free to use Google to help you figure anything out (but don't just Google \"Tic Tac Toe in Python\" otherwise you won't learn anything!) Keep in mind that this project can take anywhere between several hours to several days.\n", 20 | "\n", 21 | "There are 4 Jupyter Notebooks related to this assignment:\n", 22 | "\n", 23 | "* This Assignment Notebook\n", 24 | "* A \"Walkthrough Steps Workbook\" Notebook\n", 25 | "* A \"Complete Walkthrough Solution\" Notebook\n", 26 | "* An \"Advanced Solution\" Notebook\n", 27 | "\n", 28 | "I encourage you to just try to start the project on your own without referencing any of the notebooks. If you get stuck, check out the next lecture which is a text lecture with helpful hints and steps. If you're still stuck after that, then check out the Walkthrough Steps Workbook, which breaks up the project in steps for you to solve. Still stuck? Then check out the Complete Walkthrough Solution video for more help on approaching the project!" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "There are parts of this that will be a struggle...and that is good! I have complete faith that if you have made it this far through the course you have all the tools and knowledge to tackle this project. Remember, it's totally open book, so take your time, do a little research, and remember:\n", 36 | "\n", 37 | "## HAVE FUN!" 38 | ] 39 | } 40 | ], 41 | "metadata": { 42 | "kernelspec": { 43 | "display_name": "Python 3", 44 | "language": "python", 45 | "name": "python3" 46 | }, 47 | "language_info": { 48 | "codemirror_mode": { 49 | "name": "ipython", 50 | "version": 3 51 | }, 52 | "file_extension": ".py", 53 | "mimetype": "text/x-python", 54 | "name": "python", 55 | "nbconvert_exporter": "python", 56 | "pygments_lexer": "ipython3", 57 | "version": "3.6.2" 58 | } 59 | }, 60 | "nbformat": 4, 61 | "nbformat_minor": 1 62 | } 63 | -------------------------------------------------------------------------------- /05-Object Oriented Programming/.ipynb_checkpoints/02-Object Oriented Programming Homework-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object Oriented Programming\n", 8 | "## Homework Assignment\n", 9 | "\n", 10 | "#### Problem 1\n", 11 | "Fill in the Line class methods to accept coordinates as a pair of tuples and return the slope and distance of the line." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "class Line:\n", 21 | " \n", 22 | " def __init__(self,coor1,coor2):\n", 23 | " pass\n", 24 | " \n", 25 | " def distance(self):\n", 26 | " pass\n", 27 | " \n", 28 | " def slope(self):\n", 29 | " pass" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "# EXAMPLE OUTPUT\n", 39 | "\n", 40 | "coordinate1 = (3,2)\n", 41 | "coordinate2 = (8,10)\n", 42 | "\n", 43 | "li = Line(coordinate1,coordinate2)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 3, 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "data": { 53 | "text/plain": [ 54 | "9.433981132056603" 55 | ] 56 | }, 57 | "execution_count": 3, 58 | "metadata": {}, 59 | "output_type": "execute_result" 60 | } 61 | ], 62 | "source": [ 63 | "li.distance()" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 4, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "1.6" 75 | ] 76 | }, 77 | "execution_count": 4, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "li.slope()" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "________\n", 91 | "#### Problem 2" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "Fill in the class " 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 5, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "class Cylinder:\n", 108 | " \n", 109 | " def __init__(self,height=1,radius=1):\n", 110 | " pass\n", 111 | " \n", 112 | " def volume(self):\n", 113 | " pass\n", 114 | " \n", 115 | " def surface_area(self):\n", 116 | " pass" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 6, 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [ 125 | "# EXAMPLE OUTPUT\n", 126 | "c = Cylinder(2,3)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 7, 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "56.52" 138 | ] 139 | }, 140 | "execution_count": 7, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "c.volume()" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 8, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "data": { 156 | "text/plain": [ 157 | "94.2" 158 | ] 159 | }, 160 | "execution_count": 8, 161 | "metadata": {}, 162 | "output_type": "execute_result" 163 | } 164 | ], 165 | "source": [ 166 | "c.surface_area()" 167 | ] 168 | } 169 | ], 170 | "metadata": { 171 | "kernelspec": { 172 | "display_name": "Python 3", 173 | "language": "python", 174 | "name": "python3" 175 | }, 176 | "language_info": { 177 | "codemirror_mode": { 178 | "name": "ipython", 179 | "version": 3 180 | }, 181 | "file_extension": ".py", 182 | "mimetype": "text/x-python", 183 | "name": "python", 184 | "nbconvert_exporter": "python", 185 | "pygments_lexer": "ipython3", 186 | "version": "3.6.2" 187 | } 188 | }, 189 | "nbformat": 4, 190 | "nbformat_minor": 1 191 | } 192 | -------------------------------------------------------------------------------- /05-Object Oriented Programming/.ipynb_checkpoints/03-Object Oriented Programming Homework - Solution-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object Oriented Programming\n", 8 | "## Homework Assignment\n", 9 | "\n", 10 | "#### Problem 1\n", 11 | "Fill in the Line class methods to accept coordinates as a pair of tuples and return the slope and distance of the line." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "class Line(object):\n", 21 | " \n", 22 | " def __init__(self,coor1,coor2):\n", 23 | " self.coor1 = coor1\n", 24 | " self.coor2 = coor2\n", 25 | " \n", 26 | " def distance(self):\n", 27 | " x1,y1 = self.coor1\n", 28 | " x2,y2 = self.coor2\n", 29 | " return ((x2-x1)**2 + (y2-y1)**2)**0.5\n", 30 | " \n", 31 | " def slope(self):\n", 32 | " x1,y1 = self.coor1\n", 33 | " x2,y2 = self.coor2\n", 34 | " return (y2-y1)/(x2-x1)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 2, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "coordinate1 = (3,2)\n", 44 | "coordinate2 = (8,10)\n", 45 | "\n", 46 | "li = Line(coordinate1,coordinate2)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 3, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "data": { 56 | "text/plain": [ 57 | "9.433981132056603" 58 | ] 59 | }, 60 | "execution_count": 3, 61 | "metadata": {}, 62 | "output_type": "execute_result" 63 | } 64 | ], 65 | "source": [ 66 | "li.distance()" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 4, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "data": { 76 | "text/plain": [ 77 | "1.6" 78 | ] 79 | }, 80 | "execution_count": 4, 81 | "metadata": {}, 82 | "output_type": "execute_result" 83 | } 84 | ], 85 | "source": [ 86 | "li.slope()" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": {}, 92 | "source": [ 93 | "________\n", 94 | "#### Problem 2" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "metadata": {}, 100 | "source": [ 101 | "Fill in the class " 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 5, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "class Cylinder:\n", 111 | " \n", 112 | " def __init__(self,height=1,radius=1):\n", 113 | " self.height = height\n", 114 | " self.radius = radius\n", 115 | " \n", 116 | " def volume(self):\n", 117 | " return self.height*3.14*(self.radius)**2\n", 118 | " \n", 119 | " def surface_area(self):\n", 120 | " top = 3.14 * (self.radius)**2\n", 121 | " return (2*top) + (2*3.14*self.radius*self.height)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 6, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "c = Cylinder(2,3)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 7, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/plain": [ 141 | "56.52" 142 | ] 143 | }, 144 | "execution_count": 7, 145 | "metadata": {}, 146 | "output_type": "execute_result" 147 | } 148 | ], 149 | "source": [ 150 | "c.volume()" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 8, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "data": { 160 | "text/plain": [ 161 | "94.2" 162 | ] 163 | }, 164 | "execution_count": 8, 165 | "metadata": {}, 166 | "output_type": "execute_result" 167 | } 168 | ], 169 | "source": [ 170 | "c.surface_area()" 171 | ] 172 | } 173 | ], 174 | "metadata": { 175 | "kernelspec": { 176 | "display_name": "Python 3", 177 | "language": "python", 178 | "name": "python3" 179 | }, 180 | "language_info": { 181 | "codemirror_mode": { 182 | "name": "ipython", 183 | "version": 3 184 | }, 185 | "file_extension": ".py", 186 | "mimetype": "text/x-python", 187 | "name": "python", 188 | "nbconvert_exporter": "python", 189 | "pygments_lexer": "ipython3", 190 | "version": "3.6.2" 191 | } 192 | }, 193 | "nbformat": 4, 194 | "nbformat_minor": 1 195 | } 196 | -------------------------------------------------------------------------------- /05-Object Oriented Programming/.ipynb_checkpoints/04-OOP Challenge-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object Oriented Programming Challenge\n", 8 | "\n", 9 | "For this challenge, create a bank account class that has two attributes:\n", 10 | "\n", 11 | "* owner\n", 12 | "* balance\n", 13 | "\n", 14 | "and two methods:\n", 15 | "\n", 16 | "* deposit\n", 17 | "* withdraw\n", 18 | "\n", 19 | "As an added requirement, withdrawals may not exceed the available balance.\n", 20 | "\n", 21 | "Instantiate your class, make several deposits and withdrawals, and test to make sure the account can't be overdrawn." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "class Account:\n", 31 | " pass" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "# 1. Instantiate the class\n", 41 | "acct1 = Account('Jose',100)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 3, 47 | "metadata": {}, 48 | "outputs": [ 49 | { 50 | "name": "stdout", 51 | "output_type": "stream", 52 | "text": [ 53 | "Account owner: Jose\n", 54 | "Account balance: $100\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "# 2. Print the object\n", 60 | "print(acct1)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 4, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "data": { 70 | "text/plain": [ 71 | "'Jose'" 72 | ] 73 | }, 74 | "execution_count": 4, 75 | "metadata": {}, 76 | "output_type": "execute_result" 77 | } 78 | ], 79 | "source": [ 80 | "# 3. Show the account owner attribute\n", 81 | "acct1.owner" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 5, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "100" 93 | ] 94 | }, 95 | "execution_count": 5, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "# 4. Show the account balance attribute\n", 102 | "acct1.balance" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 6, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "Deposit Accepted\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "# 5. Make a series of deposits and withdrawals\n", 120 | "acct1.deposit(50)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 7, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "Withdrawal Accepted\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "acct1.withdraw(75)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 8, 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "Funds Unavailable!\n" 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "# 6. Make a withdrawal that exceeds the available balance\n", 155 | "acct1.withdraw(500)" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "## Good job!" 163 | ] 164 | } 165 | ], 166 | "metadata": { 167 | "kernelspec": { 168 | "display_name": "Python 3", 169 | "language": "python", 170 | "name": "python3" 171 | }, 172 | "language_info": { 173 | "codemirror_mode": { 174 | "name": "ipython", 175 | "version": 3 176 | }, 177 | "file_extension": ".py", 178 | "mimetype": "text/x-python", 179 | "name": "python", 180 | "nbconvert_exporter": "python", 181 | "pygments_lexer": "ipython3", 182 | "version": "3.6.2" 183 | } 184 | }, 185 | "nbformat": 4, 186 | "nbformat_minor": 2 187 | } 188 | -------------------------------------------------------------------------------- /05-Object Oriented Programming/.ipynb_checkpoints/05-OOP Challenge - Solution-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object Oriented Programming Challenge - Solution\n", 8 | "\n", 9 | "For this challenge, create a bank account class that has two attributes:\n", 10 | "\n", 11 | "* owner\n", 12 | "* balance\n", 13 | "\n", 14 | "and two methods:\n", 15 | "\n", 16 | "* deposit\n", 17 | "* withdraw\n", 18 | "\n", 19 | "As an added requirement, withdrawals may not exceed the available balance.\n", 20 | "\n", 21 | "Instantiate your class, make several deposits and withdrawals, and test to make sure the account can't be overdrawn." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "class Account:\n", 31 | " def __init__(self,owner,balance=0):\n", 32 | " self.owner = owner\n", 33 | " self.balance = balance\n", 34 | " \n", 35 | " def __str__(self):\n", 36 | " return f'Account owner: {self.owner}\\nAccount balance: ${self.balance}'\n", 37 | " \n", 38 | " def deposit(self,dep_amt):\n", 39 | " self.balance += dep_amt\n", 40 | " print('Deposit Accepted')\n", 41 | " \n", 42 | " def withdraw(self,wd_amt):\n", 43 | " if self.balance >= wd_amt:\n", 44 | " self.balance -= wd_amt\n", 45 | " print('Withdrawal Accepted')\n", 46 | " else:\n", 47 | " print('Funds Unavailable!')" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 2, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "# 1. Instantiate the class\n", 57 | "acct1 = Account('Jose',100)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 3, 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "Account owner: Jose\n", 70 | "Account balance: $100\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "# 2. Print the object\n", 76 | "print(acct1)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 4, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "data": { 86 | "text/plain": [ 87 | "'Jose'" 88 | ] 89 | }, 90 | "execution_count": 4, 91 | "metadata": {}, 92 | "output_type": "execute_result" 93 | } 94 | ], 95 | "source": [ 96 | "# 3. Show the account owner attribute\n", 97 | "acct1.owner" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 5, 103 | "metadata": {}, 104 | "outputs": [ 105 | { 106 | "data": { 107 | "text/plain": [ 108 | "100" 109 | ] 110 | }, 111 | "execution_count": 5, 112 | "metadata": {}, 113 | "output_type": "execute_result" 114 | } 115 | ], 116 | "source": [ 117 | "# 4. Show the account balance attribute\n", 118 | "acct1.balance" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 6, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "Deposit Accepted\n" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "# 5. Make a series of deposits and withdrawals\n", 136 | "acct1.deposit(50)" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 7, 142 | "metadata": {}, 143 | "outputs": [ 144 | { 145 | "name": "stdout", 146 | "output_type": "stream", 147 | "text": [ 148 | "Withdrawal Accepted\n" 149 | ] 150 | } 151 | ], 152 | "source": [ 153 | "acct1.withdraw(75)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 8, 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "Funds Unavailable!\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "# 6. Make a withdrawal that exceeds the available balance\n", 171 | "acct1.withdraw(500)" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "## Good job!" 179 | ] 180 | } 181 | ], 182 | "metadata": { 183 | "kernelspec": { 184 | "display_name": "Python 3", 185 | "language": "python", 186 | "name": "python3" 187 | }, 188 | "language_info": { 189 | "codemirror_mode": { 190 | "name": "ipython", 191 | "version": 3 192 | }, 193 | "file_extension": ".py", 194 | "mimetype": "text/x-python", 195 | "name": "python", 196 | "nbconvert_exporter": "python", 197 | "pygments_lexer": "ipython3", 198 | "version": "3.6.2" 199 | } 200 | }, 201 | "nbformat": 4, 202 | "nbformat_minor": 2 203 | } 204 | -------------------------------------------------------------------------------- /05-Object Oriented Programming/02-Object Oriented Programming Homework.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object Oriented Programming\n", 8 | "## Homework Assignment\n", 9 | "\n", 10 | "#### Problem 1\n", 11 | "Fill in the Line class methods to accept coordinates as a pair of tuples and return the slope and distance of the line." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "class Line:\n", 21 | " \n", 22 | " def __init__(self,coor1,coor2):\n", 23 | " pass\n", 24 | " \n", 25 | " def distance(self):\n", 26 | " pass\n", 27 | " \n", 28 | " def slope(self):\n", 29 | " pass" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "# EXAMPLE OUTPUT\n", 39 | "\n", 40 | "coordinate1 = (3,2)\n", 41 | "coordinate2 = (8,10)\n", 42 | "\n", 43 | "li = Line(coordinate1,coordinate2)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 3, 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "data": { 53 | "text/plain": [ 54 | "9.433981132056603" 55 | ] 56 | }, 57 | "execution_count": 3, 58 | "metadata": {}, 59 | "output_type": "execute_result" 60 | } 61 | ], 62 | "source": [ 63 | "li.distance()" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 4, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "1.6" 75 | ] 76 | }, 77 | "execution_count": 4, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "li.slope()" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "________\n", 91 | "#### Problem 2" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "Fill in the class " 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 5, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "class Cylinder:\n", 108 | " \n", 109 | " def __init__(self,height=1,radius=1):\n", 110 | " pass\n", 111 | " \n", 112 | " def volume(self):\n", 113 | " pass\n", 114 | " \n", 115 | " def surface_area(self):\n", 116 | " pass" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 6, 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [ 125 | "# EXAMPLE OUTPUT\n", 126 | "c = Cylinder(2,3)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 7, 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "56.52" 138 | ] 139 | }, 140 | "execution_count": 7, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "c.volume()" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 8, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "data": { 156 | "text/plain": [ 157 | "94.2" 158 | ] 159 | }, 160 | "execution_count": 8, 161 | "metadata": {}, 162 | "output_type": "execute_result" 163 | } 164 | ], 165 | "source": [ 166 | "c.surface_area()" 167 | ] 168 | } 169 | ], 170 | "metadata": { 171 | "kernelspec": { 172 | "display_name": "Python 3", 173 | "language": "python", 174 | "name": "python3" 175 | }, 176 | "language_info": { 177 | "codemirror_mode": { 178 | "name": "ipython", 179 | "version": 3 180 | }, 181 | "file_extension": ".py", 182 | "mimetype": "text/x-python", 183 | "name": "python", 184 | "nbconvert_exporter": "python", 185 | "pygments_lexer": "ipython3", 186 | "version": "3.6.2" 187 | } 188 | }, 189 | "nbformat": 4, 190 | "nbformat_minor": 1 191 | } 192 | -------------------------------------------------------------------------------- /05-Object Oriented Programming/03-Object Oriented Programming Homework - Solution.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object Oriented Programming\n", 8 | "## Homework Assignment\n", 9 | "\n", 10 | "#### Problem 1\n", 11 | "Fill in the Line class methods to accept coordinates as a pair of tuples and return the slope and distance of the line." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "class Line(object):\n", 21 | " \n", 22 | " def __init__(self,coor1,coor2):\n", 23 | " self.coor1 = coor1\n", 24 | " self.coor2 = coor2\n", 25 | " \n", 26 | " def distance(self):\n", 27 | " x1,y1 = self.coor1\n", 28 | " x2,y2 = self.coor2\n", 29 | " return ((x2-x1)**2 + (y2-y1)**2)**0.5\n", 30 | " \n", 31 | " def slope(self):\n", 32 | " x1,y1 = self.coor1\n", 33 | " x2,y2 = self.coor2\n", 34 | " return (y2-y1)/(x2-x1)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 2, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "coordinate1 = (3,2)\n", 44 | "coordinate2 = (8,10)\n", 45 | "\n", 46 | "li = Line(coordinate1,coordinate2)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 3, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "data": { 56 | "text/plain": [ 57 | "9.433981132056603" 58 | ] 59 | }, 60 | "execution_count": 3, 61 | "metadata": {}, 62 | "output_type": "execute_result" 63 | } 64 | ], 65 | "source": [ 66 | "li.distance()" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 4, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "data": { 76 | "text/plain": [ 77 | "1.6" 78 | ] 79 | }, 80 | "execution_count": 4, 81 | "metadata": {}, 82 | "output_type": "execute_result" 83 | } 84 | ], 85 | "source": [ 86 | "li.slope()" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": {}, 92 | "source": [ 93 | "________\n", 94 | "#### Problem 2" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "metadata": {}, 100 | "source": [ 101 | "Fill in the class " 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 5, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "class Cylinder:\n", 111 | " \n", 112 | " def __init__(self,height=1,radius=1):\n", 113 | " self.height = height\n", 114 | " self.radius = radius\n", 115 | " \n", 116 | " def volume(self):\n", 117 | " return self.height*3.14*(self.radius)**2\n", 118 | " \n", 119 | " def surface_area(self):\n", 120 | " top = 3.14 * (self.radius)**2\n", 121 | " return (2*top) + (2*3.14*self.radius*self.height)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 6, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "c = Cylinder(2,3)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 7, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/plain": [ 141 | "56.52" 142 | ] 143 | }, 144 | "execution_count": 7, 145 | "metadata": {}, 146 | "output_type": "execute_result" 147 | } 148 | ], 149 | "source": [ 150 | "c.volume()" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 8, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "data": { 160 | "text/plain": [ 161 | "94.2" 162 | ] 163 | }, 164 | "execution_count": 8, 165 | "metadata": {}, 166 | "output_type": "execute_result" 167 | } 168 | ], 169 | "source": [ 170 | "c.surface_area()" 171 | ] 172 | } 173 | ], 174 | "metadata": { 175 | "kernelspec": { 176 | "display_name": "Python 3", 177 | "language": "python", 178 | "name": "python3" 179 | }, 180 | "language_info": { 181 | "codemirror_mode": { 182 | "name": "ipython", 183 | "version": 3 184 | }, 185 | "file_extension": ".py", 186 | "mimetype": "text/x-python", 187 | "name": "python", 188 | "nbconvert_exporter": "python", 189 | "pygments_lexer": "ipython3", 190 | "version": "3.6.2" 191 | } 192 | }, 193 | "nbformat": 4, 194 | "nbformat_minor": 1 195 | } 196 | -------------------------------------------------------------------------------- /05-Object Oriented Programming/04-OOP Challenge.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object Oriented Programming Challenge\n", 8 | "\n", 9 | "For this challenge, create a bank account class that has two attributes:\n", 10 | "\n", 11 | "* owner\n", 12 | "* balance\n", 13 | "\n", 14 | "and two methods:\n", 15 | "\n", 16 | "* deposit\n", 17 | "* withdraw\n", 18 | "\n", 19 | "As an added requirement, withdrawals may not exceed the available balance.\n", 20 | "\n", 21 | "Instantiate your class, make several deposits and withdrawals, and test to make sure the account can't be overdrawn." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "class Account:\n", 31 | " pass" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "# 1. Instantiate the class\n", 41 | "acct1 = Account('Jose',100)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 3, 47 | "metadata": {}, 48 | "outputs": [ 49 | { 50 | "name": "stdout", 51 | "output_type": "stream", 52 | "text": [ 53 | "Account owner: Jose\n", 54 | "Account balance: $100\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "# 2. Print the object\n", 60 | "print(acct1)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 4, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "data": { 70 | "text/plain": [ 71 | "'Jose'" 72 | ] 73 | }, 74 | "execution_count": 4, 75 | "metadata": {}, 76 | "output_type": "execute_result" 77 | } 78 | ], 79 | "source": [ 80 | "# 3. Show the account owner attribute\n", 81 | "acct1.owner" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 5, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "100" 93 | ] 94 | }, 95 | "execution_count": 5, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "# 4. Show the account balance attribute\n", 102 | "acct1.balance" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 6, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "Deposit Accepted\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "# 5. Make a series of deposits and withdrawals\n", 120 | "acct1.deposit(50)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 7, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "Withdrawal Accepted\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "acct1.withdraw(75)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 8, 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "Funds Unavailable!\n" 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "# 6. Make a withdrawal that exceeds the available balance\n", 155 | "acct1.withdraw(500)" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "## Good job!" 163 | ] 164 | } 165 | ], 166 | "metadata": { 167 | "kernelspec": { 168 | "display_name": "Python 3", 169 | "language": "python", 170 | "name": "python3" 171 | }, 172 | "language_info": { 173 | "codemirror_mode": { 174 | "name": "ipython", 175 | "version": 3 176 | }, 177 | "file_extension": ".py", 178 | "mimetype": "text/x-python", 179 | "name": "python", 180 | "nbconvert_exporter": "python", 181 | "pygments_lexer": "ipython3", 182 | "version": "3.6.2" 183 | } 184 | }, 185 | "nbformat": 4, 186 | "nbformat_minor": 2 187 | } 188 | -------------------------------------------------------------------------------- /05-Object Oriented Programming/05-OOP Challenge - Solution.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object Oriented Programming Challenge - Solution\n", 8 | "\n", 9 | "For this challenge, create a bank account class that has two attributes:\n", 10 | "\n", 11 | "* owner\n", 12 | "* balance\n", 13 | "\n", 14 | "and two methods:\n", 15 | "\n", 16 | "* deposit\n", 17 | "* withdraw\n", 18 | "\n", 19 | "As an added requirement, withdrawals may not exceed the available balance.\n", 20 | "\n", 21 | "Instantiate your class, make several deposits and withdrawals, and test to make sure the account can't be overdrawn." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "class Account:\n", 31 | " def __init__(self,owner,balance=0):\n", 32 | " self.owner = owner\n", 33 | " self.balance = balance\n", 34 | " \n", 35 | " def __str__(self):\n", 36 | " return f'Account owner: {self.owner}\\nAccount balance: ${self.balance}'\n", 37 | " \n", 38 | " def deposit(self,dep_amt):\n", 39 | " self.balance += dep_amt\n", 40 | " print('Deposit Accepted')\n", 41 | " \n", 42 | " def withdraw(self,wd_amt):\n", 43 | " if self.balance >= wd_amt:\n", 44 | " self.balance -= wd_amt\n", 45 | " print('Withdrawal Accepted')\n", 46 | " else:\n", 47 | " print('Funds Unavailable!')" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 2, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "# 1. Instantiate the class\n", 57 | "acct1 = Account('Jose',100)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 3, 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "Account owner: Jose\n", 70 | "Account balance: $100\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "# 2. Print the object\n", 76 | "print(acct1)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 4, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "data": { 86 | "text/plain": [ 87 | "'Jose'" 88 | ] 89 | }, 90 | "execution_count": 4, 91 | "metadata": {}, 92 | "output_type": "execute_result" 93 | } 94 | ], 95 | "source": [ 96 | "# 3. Show the account owner attribute\n", 97 | "acct1.owner" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 5, 103 | "metadata": {}, 104 | "outputs": [ 105 | { 106 | "data": { 107 | "text/plain": [ 108 | "100" 109 | ] 110 | }, 111 | "execution_count": 5, 112 | "metadata": {}, 113 | "output_type": "execute_result" 114 | } 115 | ], 116 | "source": [ 117 | "# 4. Show the account balance attribute\n", 118 | "acct1.balance" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 6, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "Deposit Accepted\n" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "# 5. Make a series of deposits and withdrawals\n", 136 | "acct1.deposit(50)" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 7, 142 | "metadata": {}, 143 | "outputs": [ 144 | { 145 | "name": "stdout", 146 | "output_type": "stream", 147 | "text": [ 148 | "Withdrawal Accepted\n" 149 | ] 150 | } 151 | ], 152 | "source": [ 153 | "acct1.withdraw(75)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 8, 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "Funds Unavailable!\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "# 6. Make a withdrawal that exceeds the available balance\n", 171 | "acct1.withdraw(500)" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "## Good job!" 179 | ] 180 | } 181 | ], 182 | "metadata": { 183 | "kernelspec": { 184 | "display_name": "Python 3", 185 | "language": "python", 186 | "name": "python3" 187 | }, 188 | "language_info": { 189 | "codemirror_mode": { 190 | "name": "ipython", 191 | "version": 3 192 | }, 193 | "file_extension": ".py", 194 | "mimetype": "text/x-python", 195 | "name": "python", 196 | "nbconvert_exporter": "python", 197 | "pygments_lexer": "ipython3", 198 | "version": "3.6.2" 199 | } 200 | }, 201 | "nbformat": 4, 202 | "nbformat_minor": 2 203 | } 204 | -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/SubPackage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starksecurity/Pierian-Data-Complete-Python-3-Bootcamp/c2407e5f71f48d23e029eb66d0beb366bcb0e3c9/06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/SubPackage/__init__.py -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/SubPackage/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starksecurity/Pierian-Data-Complete-Python-3-Bootcamp/c2407e5f71f48d23e029eb66d0beb366bcb0e3c9/06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/SubPackage/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/SubPackage/__pycache__/mysubscript.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starksecurity/Pierian-Data-Complete-Python-3-Bootcamp/c2407e5f71f48d23e029eb66d0beb366bcb0e3c9/06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/SubPackage/__pycache__/mysubscript.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/SubPackage/mysubscript.py: -------------------------------------------------------------------------------- 1 | def sub_report(): 2 | print("Hey Im a function inside mysubscript") -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starksecurity/Pierian-Data-Complete-Python-3-Bootcamp/c2407e5f71f48d23e029eb66d0beb366bcb0e3c9/06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/__init__.py -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starksecurity/Pierian-Data-Complete-Python-3-Bootcamp/c2407e5f71f48d23e029eb66d0beb366bcb0e3c9/06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/__pycache__/some_main_script.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starksecurity/Pierian-Data-Complete-Python-3-Bootcamp/c2407e5f71f48d23e029eb66d0beb366bcb0e3c9/06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/__pycache__/some_main_script.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/MyMainPackage/some_main_script.py: -------------------------------------------------------------------------------- 1 | def report_main(): 2 | print("Hey I am in some_main_script in main package.") -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/mymodule.py: -------------------------------------------------------------------------------- 1 | def my_func(): 2 | print("Hey I am in mymodule.py") -------------------------------------------------------------------------------- /06-Modules and Packages/00-Modules_and_Packages/myprogram.py: -------------------------------------------------------------------------------- 1 | from MyMainPackage.some_main_script import report_main 2 | from MyMainPackage.SubPackage import mysubscript 3 | 4 | report_main() 5 | 6 | mysubscript.sub_report() 7 | -------------------------------------------------------------------------------- /06-Modules and Packages/01-Name_and_Main/Explanation.txt: -------------------------------------------------------------------------------- 1 | Sometimes when you are importing from a module, you would like to know whether 2 | a modules function is being used as an import, or if you are using the original 3 | .py file of that module. In this case we can use the: 4 | 5 | if __name__ == "__main__": 6 | 7 | line to determine this. For example: 8 | 9 | When your script is run by passing it as a command to the Python interpreter: 10 | 11 | python myscript.py 12 | 13 | all of the code that is at indentation level 0 gets executed. Functions and 14 | classes that are defined are, well, defined, but none of their code gets ran. 15 | Unlike other languages, there's no main() function that gets run automatically 16 | - the main() function is implicitly all the code at the top level. 17 | 18 | In this case, the top-level code is an if block. __name__ is a built-in variable 19 | which evaluate to the name of the current module. However, if a module is being 20 | run directly (as in myscript.py above), then __name__ instead is set to the 21 | string "__main__". Thus, you can test whether your script is being run directly 22 | or being imported by something else by testing 23 | 24 | if __name__ == "__main__": 25 | ... 26 | 27 | If that code is being imported into another module, the various function and 28 | class definitions will be imported, but the main() code won't get run. As a 29 | basic example, consider the following two scripts: 30 | 31 | # file one.py 32 | def func(): 33 | print("func() in one.py") 34 | 35 | print("top-level in one.py") 36 | 37 | if __name__ == "__main__": 38 | print("one.py is being run directly") 39 | else: 40 | print("one.py is being imported into another module") 41 | 42 | and then: 43 | 44 | # file two.py 45 | import one 46 | 47 | print("top-level in two.py") 48 | one.func() 49 | 50 | if __name__ == "__main__": 51 | print("two.py is being run directly") 52 | else: 53 | print("two.py is being imported into another module") 54 | 55 | Now, if you invoke the interpreter as 56 | 57 | python one.py 58 | 59 | The output will be 60 | 61 | top-level in one.py 62 | 63 | one.py is being run directly 64 | If you run two.py instead: 65 | 66 | python two.py 67 | 68 | You get 69 | 70 | top-level in one.py 71 | one.py is being imported into another module 72 | top-level in two.py 73 | func() in one.py 74 | two.py is being run directly 75 | 76 | Thus, when module one gets loaded, its __name__ equals "one" instead of __main__. 77 | -------------------------------------------------------------------------------- /06-Modules and Packages/01-Name_and_Main/one.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print("func() ran in one.py") 3 | 4 | print("top-level print inside of one.py") 5 | 6 | if __name__ == "__main__": 7 | print("one.py is being run directly") 8 | else: 9 | print("one.py is being imported into another module") 10 | -------------------------------------------------------------------------------- /06-Modules and Packages/01-Name_and_Main/two.py: -------------------------------------------------------------------------------- 1 | import one 2 | 3 | print("top-level in two.py") 4 | 5 | one.func() 6 | 7 | if __name__ == "__main__": 8 | print("two.py is being run directly") 9 | else: 10 | print("two.py is being imported into another module") 11 | -------------------------------------------------------------------------------- /06-Modules and Packages/__pycache__/file1.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starksecurity/Pierian-Data-Complete-Python-3-Bootcamp/c2407e5f71f48d23e029eb66d0beb366bcb0e3c9/06-Modules and Packages/__pycache__/file1.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules and Packages/file1.py: -------------------------------------------------------------------------------- 1 | def myfunc(x): 2 | return [num for num in range(x) if num%2==0] 3 | list1 = myfunc(11) -------------------------------------------------------------------------------- /06-Modules and Packages/file2.py: -------------------------------------------------------------------------------- 1 | import file1 2 | file1.list1.append(12) 3 | print(file1.list1) -------------------------------------------------------------------------------- /06-Modules and Packages/file3.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import file1 3 | num = int(sys.argv[1]) 4 | print(file1.myfunc(num)) -------------------------------------------------------------------------------- /07-Errors and Exception Handling/.ipynb_checkpoints/02-Errors and Exceptions Homework-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Errors and Exceptions Homework" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Problem 1\n", 15 | "Handle the exception thrown by the code below by using try and except blocks." 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [ 23 | { 24 | "ename": "TypeError", 25 | "evalue": "unsupported operand type(s) for ** or pow(): 'str' and 'int'", 26 | "output_type": "error", 27 | "traceback": [ 28 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 29 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 30 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'a'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'b'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'c'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m**\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 31 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for ** or pow(): 'str' and 'int'" 32 | ] 33 | } 34 | ], 35 | "source": [ 36 | "for i in ['a','b','c']:\n", 37 | " print(i**2)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "### Problem 2\n", 45 | "Handle the exception thrown by the code below by using try and except blocks. Then use a finally block to print 'All Done.'" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "ename": "ZeroDivisionError", 55 | "evalue": "division by zero", 56 | "output_type": "error", 57 | "traceback": [ 58 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 59 | "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 60 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mz\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 61 | "\u001b[1;31mZeroDivisionError\u001b[0m: division by zero" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "x = 5\n", 67 | "y = 0\n", 68 | "\n", 69 | "z = x/y" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "### Problem 3\n", 77 | "Write a function that asks for an integer and prints the square of it. Use a while loop with a try, except, else block to account for incorrect inputs." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 3, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "def ask():\n", 87 | " pass" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 4, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "Input an integer: null\n", 100 | "An error occurred! Please try again!\n", 101 | "Input an integer: 2\n", 102 | "Thank you, your number squared is: 4\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "ask()" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": {}, 113 | "source": [ 114 | "# Great Job!" 115 | ] 116 | } 117 | ], 118 | "metadata": { 119 | "kernelspec": { 120 | "display_name": "Python 3", 121 | "language": "python", 122 | "name": "python3" 123 | }, 124 | "language_info": { 125 | "codemirror_mode": { 126 | "name": "ipython", 127 | "version": 3 128 | }, 129 | "file_extension": ".py", 130 | "mimetype": "text/x-python", 131 | "name": "python", 132 | "nbconvert_exporter": "python", 133 | "pygments_lexer": "ipython3", 134 | "version": "3.6.2" 135 | } 136 | }, 137 | "nbformat": 4, 138 | "nbformat_minor": 1 139 | } 140 | -------------------------------------------------------------------------------- /07-Errors and Exception Handling/.ipynb_checkpoints/03-Errors and Exceptions Homework - Solution-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Errors and Exceptions Homework - Solution" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Problem 1\n", 15 | "Handle the exception thrown by the code below by using try and except blocks." 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [ 23 | { 24 | "name": "stdout", 25 | "output_type": "stream", 26 | "text": [ 27 | "An error occurred!\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "try:\n", 33 | " for i in ['a','b','c']:\n", 34 | " print(i**2)\n", 35 | "except:\n", 36 | " print(\"An error occurred!\")" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "### Problem 2\n", 44 | "Handle the exception thrown by the code below by using try and except blocks. Then use a finally block to print 'All Done.'" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 2, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Can't divide by Zero!\n", 57 | "All Done!\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "x = 5\n", 63 | "y = 0\n", 64 | "try:\n", 65 | " z = x/y\n", 66 | "except ZeroDivisionError:\n", 67 | " print(\"Can't divide by Zero!\")\n", 68 | "finally:\n", 69 | " print('All Done!')" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "### Problem 3\n", 77 | "Write a function that asks for an integer and prints the square of it. Use a while loop with a try, except, else block to account for incorrect inputs." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 3, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "def ask():\n", 87 | " \n", 88 | " while True:\n", 89 | " try:\n", 90 | " n = int(input('Input an integer: '))\n", 91 | " except:\n", 92 | " print('An error occurred! Please try again!')\n", 93 | " continue\n", 94 | " else:\n", 95 | " break\n", 96 | " \n", 97 | " \n", 98 | " print('Thank you, your number squared is: ',n**2)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 4, 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "name": "stdout", 108 | "output_type": "stream", 109 | "text": [ 110 | "Input an integer: null\n", 111 | "An error occurred! Please try again!\n", 112 | "Input an integer: 2\n", 113 | "Thank you, your number squared is: 4\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "ask()" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "metadata": {}, 124 | "source": [ 125 | "# Great Job!" 126 | ] 127 | } 128 | ], 129 | "metadata": { 130 | "kernelspec": { 131 | "display_name": "Python 3", 132 | "language": "python", 133 | "name": "python3" 134 | }, 135 | "language_info": { 136 | "codemirror_mode": { 137 | "name": "ipython", 138 | "version": 3 139 | }, 140 | "file_extension": ".py", 141 | "mimetype": "text/x-python", 142 | "name": "python", 143 | "nbconvert_exporter": "python", 144 | "pygments_lexer": "ipython3", 145 | "version": "3.6.2" 146 | } 147 | }, 148 | "nbformat": 4, 149 | "nbformat_minor": 1 150 | } 151 | -------------------------------------------------------------------------------- /07-Errors and Exception Handling/02-Errors and Exceptions Homework.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Errors and Exceptions Homework" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Problem 1\n", 15 | "Handle the exception thrown by the code below by using try and except blocks." 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [ 23 | { 24 | "ename": "TypeError", 25 | "evalue": "unsupported operand type(s) for ** or pow(): 'str' and 'int'", 26 | "output_type": "error", 27 | "traceback": [ 28 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 29 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 30 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'a'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'b'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'c'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m**\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 31 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for ** or pow(): 'str' and 'int'" 32 | ] 33 | } 34 | ], 35 | "source": [ 36 | "for i in ['a','b','c']:\n", 37 | " print(i**2)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "### Problem 2\n", 45 | "Handle the exception thrown by the code below by using try and except blocks. Then use a finally block to print 'All Done.'" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "ename": "ZeroDivisionError", 55 | "evalue": "division by zero", 56 | "output_type": "error", 57 | "traceback": [ 58 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 59 | "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 60 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mz\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 61 | "\u001b[1;31mZeroDivisionError\u001b[0m: division by zero" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "x = 5\n", 67 | "y = 0\n", 68 | "\n", 69 | "z = x/y" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "### Problem 3\n", 77 | "Write a function that asks for an integer and prints the square of it. Use a while loop with a try, except, else block to account for incorrect inputs." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 3, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "def ask():\n", 87 | " pass" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 4, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "Input an integer: null\n", 100 | "An error occurred! Please try again!\n", 101 | "Input an integer: 2\n", 102 | "Thank you, your number squared is: 4\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "ask()" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": {}, 113 | "source": [ 114 | "# Great Job!" 115 | ] 116 | } 117 | ], 118 | "metadata": { 119 | "kernelspec": { 120 | "display_name": "Python 3", 121 | "language": "python", 122 | "name": "python3" 123 | }, 124 | "language_info": { 125 | "codemirror_mode": { 126 | "name": "ipython", 127 | "version": 3 128 | }, 129 | "file_extension": ".py", 130 | "mimetype": "text/x-python", 131 | "name": "python", 132 | "nbconvert_exporter": "python", 133 | "pygments_lexer": "ipython3", 134 | "version": "3.6.2" 135 | } 136 | }, 137 | "nbformat": 4, 138 | "nbformat_minor": 1 139 | } 140 | -------------------------------------------------------------------------------- /07-Errors and Exception Handling/03-Errors and Exceptions Homework - Solution.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Errors and Exceptions Homework - Solution" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Problem 1\n", 15 | "Handle the exception thrown by the code below by using try and except blocks." 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [ 23 | { 24 | "name": "stdout", 25 | "output_type": "stream", 26 | "text": [ 27 | "An error occurred!\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "try:\n", 33 | " for i in ['a','b','c']:\n", 34 | " print(i**2)\n", 35 | "except:\n", 36 | " print(\"An error occurred!\")" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "### Problem 2\n", 44 | "Handle the exception thrown by the code below by using try and except blocks. Then use a finally block to print 'All Done.'" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 2, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Can't divide by Zero!\n", 57 | "All Done!\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "x = 5\n", 63 | "y = 0\n", 64 | "try:\n", 65 | " z = x/y\n", 66 | "except ZeroDivisionError:\n", 67 | " print(\"Can't divide by Zero!\")\n", 68 | "finally:\n", 69 | " print('All Done!')" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "### Problem 3\n", 77 | "Write a function that asks for an integer and prints the square of it. Use a while loop with a try, except, else block to account for incorrect inputs." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 3, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "def ask():\n", 87 | " \n", 88 | " while True:\n", 89 | " try:\n", 90 | " n = int(input('Input an integer: '))\n", 91 | " except:\n", 92 | " print('An error occurred! Please try again!')\n", 93 | " continue\n", 94 | " else:\n", 95 | " break\n", 96 | " \n", 97 | " \n", 98 | " print('Thank you, your number squared is: ',n**2)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 4, 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "name": "stdout", 108 | "output_type": "stream", 109 | "text": [ 110 | "Input an integer: null\n", 111 | "An error occurred! Please try again!\n", 112 | "Input an integer: 2\n", 113 | "Thank you, your number squared is: 4\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "ask()" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "metadata": {}, 124 | "source": [ 125 | "# Great Job!" 126 | ] 127 | } 128 | ], 129 | "metadata": { 130 | "kernelspec": { 131 | "display_name": "Python 3", 132 | "language": "python", 133 | "name": "python3" 134 | }, 135 | "language_info": { 136 | "codemirror_mode": { 137 | "name": "ipython", 138 | "version": 3 139 | }, 140 | "file_extension": ".py", 141 | "mimetype": "text/x-python", 142 | "name": "python", 143 | "nbconvert_exporter": "python", 144 | "pygments_lexer": "ipython3", 145 | "version": "3.6.2" 146 | } 147 | }, 148 | "nbformat": 4, 149 | "nbformat_minor": 1 150 | } 151 | -------------------------------------------------------------------------------- /07-Errors and Exception Handling/__pycache__/cap.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starksecurity/Pierian-Data-Complete-Python-3-Bootcamp/c2407e5f71f48d23e029eb66d0beb366bcb0e3c9/07-Errors and Exception Handling/__pycache__/cap.cpython-36.pyc -------------------------------------------------------------------------------- /07-Errors and Exception Handling/cap.py: -------------------------------------------------------------------------------- 1 | def cap_text(text): 2 | return text.title() # replace .capitalize() with .title() -------------------------------------------------------------------------------- /07-Errors and Exception Handling/simple1.py: -------------------------------------------------------------------------------- 1 | """ 2 | A very simple script. 3 | """ 4 | 5 | def myfunc(): 6 | """ 7 | An extremely simple function. 8 | """ 9 | first = 1 10 | second = 2 11 | print(first) 12 | print(second) 13 | 14 | myfunc() -------------------------------------------------------------------------------- /07-Errors and Exception Handling/simple2.py: -------------------------------------------------------------------------------- 1 | """ 2 | A very simple script. 3 | """ 4 | 5 | def myfunc(): 6 | """ 7 | An extremely simple function. 8 | """ 9 | first = 1 10 | second = 2 11 | print(first) 12 | print('second') 13 | 14 | myfunc() -------------------------------------------------------------------------------- /07-Errors and Exception Handling/test_cap.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import cap 3 | 4 | class TestCap(unittest.TestCase): 5 | 6 | def test_one_word(self): 7 | text = 'python' 8 | result = cap.cap_text(text) 9 | self.assertEqual(result, 'Python') 10 | 11 | def test_multiple_words(self): 12 | text = 'monty python' 13 | result = cap.cap_text(text) 14 | self.assertEqual(result, 'Monty Python') 15 | 16 | def test_with_apostrophes(self): 17 | text = "monty python's flying circus" 18 | result = cap.cap_text(text) 19 | self.assertEqual(result, "Monty Python's Flying Circus") 20 | 21 | if __name__ == '__main__': 22 | unittest.main() -------------------------------------------------------------------------------- /07-Errors and Exception Handling/testfile: -------------------------------------------------------------------------------- 1 | Test write statement -------------------------------------------------------------------------------- /08-Milestone Project - 2/.ipynb_checkpoints/01-Milestone Project 2 - Assignment-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Milestone Project 2 - Blackjack Game\n", 8 | "In this milestone project you will be creating a Complete BlackJack Card Game in Python.\n", 9 | "\n", 10 | "Here are the requirements:\n", 11 | "\n", 12 | "* You need to create a simple text-based [BlackJack](https://en.wikipedia.org/wiki/Blackjack) game\n", 13 | "* The game needs to have one player versus an automated dealer.\n", 14 | "* The player can stand or hit.\n", 15 | "* The player must be able to pick their betting amount.\n", 16 | "* You need to keep track of the player's total money.\n", 17 | "* You need to alert the player of wins, losses, or busts, etc...\n", 18 | "\n", 19 | "And most importantly:\n", 20 | "\n", 21 | "* **You must use OOP and classes in some portion of your game. You can not just use functions in your game. Use classes to help you define the Deck and the Player's hand. There are many right ways to do this, so explore it well!**\n", 22 | "\n", 23 | "\n", 24 | "Feel free to expand this game. Try including multiple players. Try adding in Double-Down and card splits! Remember to you are free to use any resources you want and as always:\n", 25 | "\n", 26 | "# HAVE FUN!" 27 | ] 28 | } 29 | ], 30 | "metadata": { 31 | "kernelspec": { 32 | "display_name": "Python 3", 33 | "language": "python", 34 | "name": "python3" 35 | }, 36 | "language_info": { 37 | "codemirror_mode": { 38 | "name": "ipython", 39 | "version": 3 40 | }, 41 | "file_extension": ".py", 42 | "mimetype": "text/x-python", 43 | "name": "python", 44 | "nbconvert_exporter": "python", 45 | "pygments_lexer": "ipython3", 46 | "version": "3.6.2" 47 | } 48 | }, 49 | "nbformat": 4, 50 | "nbformat_minor": 1 51 | } 52 | -------------------------------------------------------------------------------- /08-Milestone Project - 2/01-Milestone Project 2 - Assignment.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Milestone Project 2 - Blackjack Game\n", 8 | "In this milestone project you will be creating a Complete BlackJack Card Game in Python.\n", 9 | "\n", 10 | "Here are the requirements:\n", 11 | "\n", 12 | "* You need to create a simple text-based [BlackJack](https://en.wikipedia.org/wiki/Blackjack) game\n", 13 | "* The game needs to have one player versus an automated dealer.\n", 14 | "* The player can stand or hit.\n", 15 | "* The player must be able to pick their betting amount.\n", 16 | "* You need to keep track of the player's total money.\n", 17 | "* You need to alert the player of wins, losses, or busts, etc...\n", 18 | "\n", 19 | "And most importantly:\n", 20 | "\n", 21 | "* **You must use OOP and classes in some portion of your game. You can not just use functions in your game. Use classes to help you define the Deck and the Player's hand. There are many right ways to do this, so explore it well!**\n", 22 | "\n", 23 | "\n", 24 | "Feel free to expand this game. Try including multiple players. Try adding in Double-Down and card splits! Remember to you are free to use any resources you want and as always:\n", 25 | "\n", 26 | "# HAVE FUN!" 27 | ] 28 | } 29 | ], 30 | "metadata": { 31 | "kernelspec": { 32 | "display_name": "Python 3", 33 | "language": "python", 34 | "name": "python3" 35 | }, 36 | "language_info": { 37 | "codemirror_mode": { 38 | "name": "ipython", 39 | "version": 3 40 | }, 41 | "file_extension": ".py", 42 | "mimetype": "text/x-python", 43 | "name": "python", 44 | "nbconvert_exporter": "python", 45 | "pygments_lexer": "ipython3", 46 | "version": "3.6.2" 47 | } 48 | }, 49 | "nbformat": 4, 50 | "nbformat_minor": 1 51 | } 52 | -------------------------------------------------------------------------------- /09-Built-in Functions/.ipynb_checkpoints/03-Filter-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# filter\n", 8 | "\n", 9 | "The function filter(function, list) offers a convenient way to filter out all the elements of an iterable, for which the function returns True. \n", 10 | "\n", 11 | "The function filter(function,list) needs a function as its first argument. The function needs to return a Boolean value (either True or False). This function will be applied to every element of the iterable. Only if the function returns True will the element of the iterable be included in the result.\n", 12 | "\n", 13 | "Like map(), filter() returns an *iterator* - that is, filter yields one result at a time as needed. Iterators and generators will be covered in an upcoming lecture. For now, since our examples are so small, we will cast filter() as a list to see our results immediately.\n", 14 | "\n", 15 | "Let's see some examples:" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "#First let's make a function\n", 25 | "def even_check(num):\n", 26 | " if num%2 ==0:\n", 27 | " return True" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "Now let's filter a list of numbers. Note: putting the function into filter without any parentheses might feel strange, but keep in mind that functions are objects as well." 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 2, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "data": { 44 | "text/plain": [ 45 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" 46 | ] 47 | }, 48 | "execution_count": 2, 49 | "metadata": {}, 50 | "output_type": "execute_result" 51 | } 52 | ], 53 | "source": [ 54 | "lst =range(20)\n", 55 | "\n", 56 | "list(filter(even_check,lst))" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "filter() is more commonly used with lambda functions, because we usually use filter for a quick job where we don't want to write an entire function. Let's repeat the example above using a lambda expression:" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" 75 | ] 76 | }, 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "list(filter(lambda x: x%2==0,lst))" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "Great! You should now have a solid understanding of filter() and how to apply it to your code!" 91 | ] 92 | } 93 | ], 94 | "metadata": { 95 | "kernelspec": { 96 | "display_name": "Python 3", 97 | "language": "python", 98 | "name": "python3" 99 | }, 100 | "language_info": { 101 | "codemirror_mode": { 102 | "name": "ipython", 103 | "version": 3 104 | }, 105 | "file_extension": ".py", 106 | "mimetype": "text/x-python", 107 | "name": "python", 108 | "nbconvert_exporter": "python", 109 | "pygments_lexer": "ipython3", 110 | "version": "3.6.2" 111 | } 112 | }, 113 | "nbformat": 4, 114 | "nbformat_minor": 1 115 | } 116 | -------------------------------------------------------------------------------- /09-Built-in Functions/.ipynb_checkpoints/05-Enumerate-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# enumerate()\n", 8 | "\n", 9 | "In this lecture we will learn about an extremely useful built-in function: enumerate(). Enumerate allows you to keep a count as you iterate through an object. It does this by returning a tuple in the form (count,element). The function itself is equivalent to:\n", 10 | "\n", 11 | " def enumerate(sequence, start=0):\n", 12 | " n = start\n", 13 | " for elem in sequence:\n", 14 | " yield n, elem\n", 15 | " n += 1\n", 16 | "\n", 17 | "## Example" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 1, 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "name": "stdout", 27 | "output_type": "stream", 28 | "text": [ 29 | "0\n", 30 | "a\n", 31 | "1\n", 32 | "b\n", 33 | "2\n", 34 | "c\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "lst = ['a','b','c']\n", 40 | "\n", 41 | "for number,item in enumerate(lst):\n", 42 | " print(number)\n", 43 | " print(item)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "enumerate() becomes particularly useful when you have a case where you need to have some sort of tracker. For example:" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 2, 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "a\n", 63 | "b\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "for count,item in enumerate(lst):\n", 69 | " if count >= 2:\n", 70 | " break\n", 71 | " else:\n", 72 | " print(item)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "enumerate() takes an optional \"start\" argument to override the default value of zero:" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 3, 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "data": { 89 | "text/plain": [ 90 | "[(3, 'March'), (4, 'April'), (5, 'May'), (6, 'June')]" 91 | ] 92 | }, 93 | "execution_count": 3, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "months = ['March','April','May','June']\n", 100 | "\n", 101 | "list(enumerate(months,start=3))" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "Great! You should now have a good understanding of enumerate and its potential use cases." 109 | ] 110 | } 111 | ], 112 | "metadata": { 113 | "kernelspec": { 114 | "display_name": "Python 3", 115 | "language": "python", 116 | "name": "python3" 117 | }, 118 | "language_info": { 119 | "codemirror_mode": { 120 | "name": "ipython", 121 | "version": 3 122 | }, 123 | "file_extension": ".py", 124 | "mimetype": "text/x-python", 125 | "name": "python", 126 | "nbconvert_exporter": "python", 127 | "pygments_lexer": "ipython3", 128 | "version": "3.6.2" 129 | } 130 | }, 131 | "nbformat": 4, 132 | "nbformat_minor": 1 133 | } 134 | -------------------------------------------------------------------------------- /09-Built-in Functions/.ipynb_checkpoints/06-all() and any()-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# all() and any()" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "all() and any() are built-in functions in Python that allow us to conveniently check for boolean matching in an iterable. all() will return True if all elements in an iterable are True. It is the same as this function code:\n", 15 | "\n", 16 | " def all(iterable):\n", 17 | " for element in iterable:\n", 18 | " if not element:\n", 19 | " return False\n", 20 | " return True\n", 21 | " \n", 22 | "any() will return True if any of the elements in the iterable are True. It is equivalent to the following function code:\n", 23 | "\n", 24 | " def any(iterable):\n", 25 | " for element in iterable:\n", 26 | " if element:\n", 27 | " return True\n", 28 | " return False\n", 29 | " " 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "Let's see a few examples of these functions. They should be fairly straightforward:" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 1, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "lst = [True,True,False,True]" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "data": { 55 | "text/plain": [ 56 | "False" 57 | ] 58 | }, 59 | "execution_count": 2, 60 | "metadata": {}, 61 | "output_type": "execute_result" 62 | } 63 | ], 64 | "source": [ 65 | "all(lst)" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "Returns False because not all elements are True." 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "data": { 82 | "text/plain": [ 83 | "True" 84 | ] 85 | }, 86 | "execution_count": 3, 87 | "metadata": {}, 88 | "output_type": "execute_result" 89 | } 90 | ], 91 | "source": [ 92 | "any(lst)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "Returns True because at least one of the elements in the list is True" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "There you have it, you should have an understanding of how to use any() and all() in your code." 107 | ] 108 | } 109 | ], 110 | "metadata": { 111 | "kernelspec": { 112 | "display_name": "Python 3", 113 | "language": "python", 114 | "name": "python3" 115 | }, 116 | "language_info": { 117 | "codemirror_mode": { 118 | "name": "ipython", 119 | "version": 3 120 | }, 121 | "file_extension": ".py", 122 | "mimetype": "text/x-python", 123 | "name": "python", 124 | "nbconvert_exporter": "python", 125 | "pygments_lexer": "ipython3", 126 | "version": "3.6.2" 127 | } 128 | }, 129 | "nbformat": 4, 130 | "nbformat_minor": 1 131 | } 132 | -------------------------------------------------------------------------------- /09-Built-in Functions/.ipynb_checkpoints/07-Complex-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# complex()\n", 8 | "\n", 9 | "complex() returns a complex number with the value real + imag*1j or converts a string or number to a complex number. \n", 10 | "\n", 11 | "If the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. The second parameter can never be a string. Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the constructor serves as a numeric conversion like int and float. If both arguments are omitted, returns 0j.\n", 12 | "\n", 13 | "If you are doing math or engineering that requires complex numbers (such as dynamics, control systems, or impedance of a circuit) this is a useful tool to have in Python.\n", 14 | "\n", 15 | "Let's see some examples:" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [ 23 | { 24 | "data": { 25 | "text/plain": [ 26 | "(2+3j)" 27 | ] 28 | }, 29 | "execution_count": 1, 30 | "metadata": {}, 31 | "output_type": "execute_result" 32 | } 33 | ], 34 | "source": [ 35 | "# Create 2+3j\n", 36 | "complex(2,3)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/plain": [ 47 | "(10+1j)" 48 | ] 49 | }, 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "output_type": "execute_result" 53 | } 54 | ], 55 | "source": [ 56 | "complex(10,1)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "We can also pass strings:" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "(12+2j)" 75 | ] 76 | }, 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "complex('12+2j')" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "That's really all there is to this useful function. Keep it in mind if you are ever dealing with complex numbers in Python!" 91 | ] 92 | } 93 | ], 94 | "metadata": { 95 | "kernelspec": { 96 | "display_name": "Python 3", 97 | "language": "python", 98 | "name": "python3" 99 | }, 100 | "language_info": { 101 | "codemirror_mode": { 102 | "name": "ipython", 103 | "version": 3 104 | }, 105 | "file_extension": ".py", 106 | "mimetype": "text/x-python", 107 | "name": "python", 108 | "nbconvert_exporter": "python", 109 | "pygments_lexer": "ipython3", 110 | "version": "3.6.2" 111 | } 112 | }, 113 | "nbformat": 4, 114 | "nbformat_minor": 1 115 | } 116 | -------------------------------------------------------------------------------- /09-Built-in Functions/03-Filter.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# filter\n", 8 | "\n", 9 | "The function filter(function, list) offers a convenient way to filter out all the elements of an iterable, for which the function returns True. \n", 10 | "\n", 11 | "The function filter(function,list) needs a function as its first argument. The function needs to return a Boolean value (either True or False). This function will be applied to every element of the iterable. Only if the function returns True will the element of the iterable be included in the result.\n", 12 | "\n", 13 | "Like map(), filter() returns an *iterator* - that is, filter yields one result at a time as needed. Iterators and generators will be covered in an upcoming lecture. For now, since our examples are so small, we will cast filter() as a list to see our results immediately.\n", 14 | "\n", 15 | "Let's see some examples:" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "#First let's make a function\n", 25 | "def even_check(num):\n", 26 | " if num%2 ==0:\n", 27 | " return True" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "Now let's filter a list of numbers. Note: putting the function into filter without any parentheses might feel strange, but keep in mind that functions are objects as well." 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 2, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "data": { 44 | "text/plain": [ 45 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" 46 | ] 47 | }, 48 | "execution_count": 2, 49 | "metadata": {}, 50 | "output_type": "execute_result" 51 | } 52 | ], 53 | "source": [ 54 | "lst =range(20)\n", 55 | "\n", 56 | "list(filter(even_check,lst))" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "filter() is more commonly used with lambda functions, because we usually use filter for a quick job where we don't want to write an entire function. Let's repeat the example above using a lambda expression:" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" 75 | ] 76 | }, 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "list(filter(lambda x: x%2==0,lst))" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "Great! You should now have a solid understanding of filter() and how to apply it to your code!" 91 | ] 92 | } 93 | ], 94 | "metadata": { 95 | "kernelspec": { 96 | "display_name": "Python 3", 97 | "language": "python", 98 | "name": "python3" 99 | }, 100 | "language_info": { 101 | "codemirror_mode": { 102 | "name": "ipython", 103 | "version": 3 104 | }, 105 | "file_extension": ".py", 106 | "mimetype": "text/x-python", 107 | "name": "python", 108 | "nbconvert_exporter": "python", 109 | "pygments_lexer": "ipython3", 110 | "version": "3.6.2" 111 | } 112 | }, 113 | "nbformat": 4, 114 | "nbformat_minor": 1 115 | } 116 | -------------------------------------------------------------------------------- /09-Built-in Functions/05-Enumerate.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# enumerate()\n", 8 | "\n", 9 | "In this lecture we will learn about an extremely useful built-in function: enumerate(). Enumerate allows you to keep a count as you iterate through an object. It does this by returning a tuple in the form (count,element). The function itself is equivalent to:\n", 10 | "\n", 11 | " def enumerate(sequence, start=0):\n", 12 | " n = start\n", 13 | " for elem in sequence:\n", 14 | " yield n, elem\n", 15 | " n += 1\n", 16 | "\n", 17 | "## Example" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 1, 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "name": "stdout", 27 | "output_type": "stream", 28 | "text": [ 29 | "0\n", 30 | "a\n", 31 | "1\n", 32 | "b\n", 33 | "2\n", 34 | "c\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "lst = ['a','b','c']\n", 40 | "\n", 41 | "for number,item in enumerate(lst):\n", 42 | " print(number)\n", 43 | " print(item)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "enumerate() becomes particularly useful when you have a case where you need to have some sort of tracker. For example:" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 2, 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "a\n", 63 | "b\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "for count,item in enumerate(lst):\n", 69 | " if count >= 2:\n", 70 | " break\n", 71 | " else:\n", 72 | " print(item)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "enumerate() takes an optional \"start\" argument to override the default value of zero:" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 3, 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "data": { 89 | "text/plain": [ 90 | "[(3, 'March'), (4, 'April'), (5, 'May'), (6, 'June')]" 91 | ] 92 | }, 93 | "execution_count": 3, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "months = ['March','April','May','June']\n", 100 | "\n", 101 | "list(enumerate(months,start=3))" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "Great! You should now have a good understanding of enumerate and its potential use cases." 109 | ] 110 | } 111 | ], 112 | "metadata": { 113 | "kernelspec": { 114 | "display_name": "Python 3", 115 | "language": "python", 116 | "name": "python3" 117 | }, 118 | "language_info": { 119 | "codemirror_mode": { 120 | "name": "ipython", 121 | "version": 3 122 | }, 123 | "file_extension": ".py", 124 | "mimetype": "text/x-python", 125 | "name": "python", 126 | "nbconvert_exporter": "python", 127 | "pygments_lexer": "ipython3", 128 | "version": "3.6.2" 129 | } 130 | }, 131 | "nbformat": 4, 132 | "nbformat_minor": 1 133 | } 134 | -------------------------------------------------------------------------------- /09-Built-in Functions/06-all() and any().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# all() and any()" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "all() and any() are built-in functions in Python that allow us to conveniently check for boolean matching in an iterable. all() will return True if all elements in an iterable are True. It is the same as this function code:\n", 15 | "\n", 16 | " def all(iterable):\n", 17 | " for element in iterable:\n", 18 | " if not element:\n", 19 | " return False\n", 20 | " return True\n", 21 | " \n", 22 | "any() will return True if any of the elements in the iterable are True. It is equivalent to the following function code:\n", 23 | "\n", 24 | " def any(iterable):\n", 25 | " for element in iterable:\n", 26 | " if element:\n", 27 | " return True\n", 28 | " return False\n", 29 | " " 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "Let's see a few examples of these functions. They should be fairly straightforward:" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 1, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "lst = [True,True,False,True]" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "data": { 55 | "text/plain": [ 56 | "False" 57 | ] 58 | }, 59 | "execution_count": 2, 60 | "metadata": {}, 61 | "output_type": "execute_result" 62 | } 63 | ], 64 | "source": [ 65 | "all(lst)" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "Returns False because not all elements are True." 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "data": { 82 | "text/plain": [ 83 | "True" 84 | ] 85 | }, 86 | "execution_count": 3, 87 | "metadata": {}, 88 | "output_type": "execute_result" 89 | } 90 | ], 91 | "source": [ 92 | "any(lst)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "Returns True because at least one of the elements in the list is True" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "There you have it, you should have an understanding of how to use any() and all() in your code." 107 | ] 108 | } 109 | ], 110 | "metadata": { 111 | "kernelspec": { 112 | "display_name": "Python 3", 113 | "language": "python", 114 | "name": "python3" 115 | }, 116 | "language_info": { 117 | "codemirror_mode": { 118 | "name": "ipython", 119 | "version": 3 120 | }, 121 | "file_extension": ".py", 122 | "mimetype": "text/x-python", 123 | "name": "python", 124 | "nbconvert_exporter": "python", 125 | "pygments_lexer": "ipython3", 126 | "version": "3.6.2" 127 | } 128 | }, 129 | "nbformat": 4, 130 | "nbformat_minor": 1 131 | } 132 | -------------------------------------------------------------------------------- /09-Built-in Functions/07-Complex.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# complex()\n", 8 | "\n", 9 | "complex() returns a complex number with the value real + imag*1j or converts a string or number to a complex number. \n", 10 | "\n", 11 | "If the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. The second parameter can never be a string. Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the constructor serves as a numeric conversion like int and float. If both arguments are omitted, returns 0j.\n", 12 | "\n", 13 | "If you are doing math or engineering that requires complex numbers (such as dynamics, control systems, or impedance of a circuit) this is a useful tool to have in Python.\n", 14 | "\n", 15 | "Let's see some examples:" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [ 23 | { 24 | "data": { 25 | "text/plain": [ 26 | "(2+3j)" 27 | ] 28 | }, 29 | "execution_count": 1, 30 | "metadata": {}, 31 | "output_type": "execute_result" 32 | } 33 | ], 34 | "source": [ 35 | "# Create 2+3j\n", 36 | "complex(2,3)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/plain": [ 47 | "(10+1j)" 48 | ] 49 | }, 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "output_type": "execute_result" 53 | } 54 | ], 55 | "source": [ 56 | "complex(10,1)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "We can also pass strings:" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "(12+2j)" 75 | ] 76 | }, 77 | "execution_count": 3, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "complex('12+2j')" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "That's really all there is to this useful function. Keep it in mind if you are ever dealing with complex numbers in Python!" 91 | ] 92 | } 93 | ], 94 | "metadata": { 95 | "kernelspec": { 96 | "display_name": "Python 3", 97 | "language": "python", 98 | "name": "python3" 99 | }, 100 | "language_info": { 101 | "codemirror_mode": { 102 | "name": "ipython", 103 | "version": 3 104 | }, 105 | "file_extension": ".py", 106 | "mimetype": "text/x-python", 107 | "name": "python", 108 | "nbconvert_exporter": "python", 109 | "pygments_lexer": "ipython3", 110 | "version": "3.6.2" 111 | } 112 | }, 113 | "nbformat": 4, 114 | "nbformat_minor": 1 115 | } 116 | -------------------------------------------------------------------------------- /10-Python Decorators/.ipynb_checkpoints/02-Decorators Homework-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Decorators Homework (Optional)\n", 8 | "\n", 9 | "Since you won't run into decorators until further in your coding career, this homework is optional. Check out the Web Framework [Flask](http://flask.pocoo.org/). You can use Flask to create web pages with Python (as long as you know some HTML and CSS) and they use decorators a lot! Learn how they use [view decorators](http://flask.pocoo.org/docs/0.12/patterns/viewdecorators/). Don't worry if you don't completely understand everything about Flask, the main point of this optional homework is that you have an awareness of decorators in Web Frameworks. That way if you decide to become a \"Full-Stack\" Python Web Developer, you won't find yourself perplexed by decorators. You can also check out [Django](https://www.djangoproject.com/) another (and more popular) web framework for Python which is a bit more heavy duty.\n", 10 | "\n", 11 | "Also for some additional info:\n", 12 | "\n", 13 | "A framework is a type of software library that provides generic functionality which can be extended by the programmer to build applications. Flask and Django are good examples of frameworks intended for web development.\n", 14 | "\n", 15 | "A framework is distinguished from a simple library or API. An API is a piece of software that a developer can use in his or her application. A framework is more encompassing: your entire application is structured around the framework (i.e. it provides the framework around which you build your software).\n", 16 | "\n", 17 | "## Great job!" 18 | ] 19 | } 20 | ], 21 | "metadata": { 22 | "kernelspec": { 23 | "display_name": "Python 3", 24 | "language": "python", 25 | "name": "python3" 26 | }, 27 | "language_info": { 28 | "codemirror_mode": { 29 | "name": "ipython", 30 | "version": 3 31 | }, 32 | "file_extension": ".py", 33 | "mimetype": "text/x-python", 34 | "name": "python", 35 | "nbconvert_exporter": "python", 36 | "pygments_lexer": "ipython3", 37 | "version": "3.6.2" 38 | } 39 | }, 40 | "nbformat": 4, 41 | "nbformat_minor": 1 42 | } 43 | -------------------------------------------------------------------------------- /10-Python Decorators/02-Decorators Homework.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Decorators Homework (Optional)\n", 8 | "\n", 9 | "Since you won't run into decorators until further in your coding career, this homework is optional. Check out the Web Framework [Flask](http://flask.pocoo.org/). You can use Flask to create web pages with Python (as long as you know some HTML and CSS) and they use decorators a lot! Learn how they use [view decorators](http://flask.pocoo.org/docs/0.12/patterns/viewdecorators/). Don't worry if you don't completely understand everything about Flask, the main point of this optional homework is that you have an awareness of decorators in Web Frameworks. That way if you decide to become a \"Full-Stack\" Python Web Developer, you won't find yourself perplexed by decorators. You can also check out [Django](https://www.djangoproject.com/) another (and more popular) web framework for Python which is a bit more heavy duty.\n", 10 | "\n", 11 | "Also for some additional info:\n", 12 | "\n", 13 | "A framework is a type of software library that provides generic functionality which can be extended by the programmer to build applications. Flask and Django are good examples of frameworks intended for web development.\n", 14 | "\n", 15 | "A framework is distinguished from a simple library or API. An API is a piece of software that a developer can use in his or her application. A framework is more encompassing: your entire application is structured around the framework (i.e. it provides the framework around which you build your software).\n", 16 | "\n", 17 | "## Great job!" 18 | ] 19 | } 20 | ], 21 | "metadata": { 22 | "kernelspec": { 23 | "display_name": "Python 3", 24 | "language": "python", 25 | "name": "python3" 26 | }, 27 | "language_info": { 28 | "codemirror_mode": { 29 | "name": "ipython", 30 | "version": 3 31 | }, 32 | "file_extension": ".py", 33 | "mimetype": "text/x-python", 34 | "name": "python", 35 | "nbconvert_exporter": "python", 36 | "pygments_lexer": "ipython3", 37 | "version": "3.6.2" 38 | } 39 | }, 40 | "nbformat": 4, 41 | "nbformat_minor": 1 42 | } 43 | -------------------------------------------------------------------------------- /11-Python Generators/.ipynb_checkpoints/02-Iterators and Generators Homework-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Iterators and Generators Homework \n", 8 | "\n", 9 | "### Problem 1\n", 10 | "\n", 11 | "Create a generator that generates the squares of numbers up to some number N." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "def gensquares(N):\n", 21 | "\n", 22 | " pass" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 2, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "0\n", 35 | "1\n", 36 | "4\n", 37 | "9\n", 38 | "16\n", 39 | "25\n", 40 | "36\n", 41 | "49\n", 42 | "64\n", 43 | "81\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "for x in gensquares(10):\n", 49 | " print(x)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "### Problem 2\n", 57 | "\n", 58 | "Create a generator that yields \"n\" random numbers between a low and high number (that are inputs).
Note: Use the random library. For example:" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 3, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "data": { 68 | "text/plain": [ 69 | "9" 70 | ] 71 | }, 72 | "execution_count": 3, 73 | "metadata": {}, 74 | "output_type": "execute_result" 75 | } 76 | ], 77 | "source": [ 78 | "import random\n", 79 | "\n", 80 | "random.randint(1,10)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 4, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "def rand_num(low,high,n):\n", 90 | "\n", 91 | " pass" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 5, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "6\n", 104 | "1\n", 105 | "10\n", 106 | "5\n", 107 | "8\n", 108 | "2\n", 109 | "8\n", 110 | "5\n", 111 | "4\n", 112 | "5\n", 113 | "1\n", 114 | "4\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "for num in rand_num(1,10,12):\n", 120 | " print(num)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "### Problem 3\n", 128 | "\n", 129 | "Use the iter() function to convert the string below into an iterator:\n" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "s = 'hello'\n", 139 | "\n", 140 | "#code here" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "### Problem 4\n", 148 | "Explain a use case for a generator using a yield statement where you would not want to use a normal function with a return statement.





\n", 149 | "\n" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "### Extra Credit!\n", 157 | "Can you explain what *gencomp* is in the code below? (Note: We never covered this in lecture! You will have to do some Googling/Stack Overflowing!)" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 6, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "4\n", 170 | "5\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "my_list = [1,2,3,4,5]\n", 176 | "\n", 177 | "gencomp = (item for item in my_list if item > 3)\n", 178 | "\n", 179 | "for item in gencomp:\n", 180 | " print(item)" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "Hint: Google *generator comprehension*!\n", 188 | "\n", 189 | "# Great Job!" 190 | ] 191 | } 192 | ], 193 | "metadata": { 194 | "kernelspec": { 195 | "display_name": "Python 3", 196 | "language": "python", 197 | "name": "python3" 198 | }, 199 | "language_info": { 200 | "codemirror_mode": { 201 | "name": "ipython", 202 | "version": 3 203 | }, 204 | "file_extension": ".py", 205 | "mimetype": "text/x-python", 206 | "name": "python", 207 | "nbconvert_exporter": "python", 208 | "pygments_lexer": "ipython3", 209 | "version": "3.6.2" 210 | } 211 | }, 212 | "nbformat": 4, 213 | "nbformat_minor": 1 214 | } 215 | -------------------------------------------------------------------------------- /11-Python Generators/.ipynb_checkpoints/03-Iterators and Generators Homework - Solution-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Iterators and Generators Homework - Solution\n", 8 | "\n", 9 | "### Problem 1\n", 10 | "\n", 11 | "Create a generator that generates the squares of numbers up to some number N." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "def gensquares(N):\n", 21 | " for i in range(N):\n", 22 | " yield i**2" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 2, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "0\n", 35 | "1\n", 36 | "4\n", 37 | "9\n", 38 | "16\n", 39 | "25\n", 40 | "36\n", 41 | "49\n", 42 | "64\n", 43 | "81\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "for x in gensquares(10):\n", 49 | " print(x)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "### Problem 2\n", 57 | "\n", 58 | "Create a generator that yields \"n\" random numbers between a low and high number (that are inputs).
Note: Use the random library. For example:" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 3, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "data": { 68 | "text/plain": [ 69 | "3" 70 | ] 71 | }, 72 | "execution_count": 3, 73 | "metadata": {}, 74 | "output_type": "execute_result" 75 | } 76 | ], 77 | "source": [ 78 | "import random\n", 79 | "\n", 80 | "random.randint(1,10)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 4, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "def rand_num(low,high,n):\n", 90 | " \n", 91 | " for i in range(n):\n", 92 | " yield random.randint(low, high)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 5, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "3\n", 105 | "9\n", 106 | "6\n", 107 | "10\n", 108 | "8\n", 109 | "4\n", 110 | "5\n", 111 | "5\n", 112 | "5\n", 113 | "3\n", 114 | "5\n", 115 | "8\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "for num in rand_num(1,10,12):\n", 121 | " print(num)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "### Problem 3\n", 129 | "\n", 130 | "Use the iter() function to convert the string below into an iterator:\n" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 6, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "h\n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "s = 'hello'\n", 148 | "\n", 149 | "s = iter(s)\n", 150 | "\n", 151 | "print(next(s))" 152 | ] 153 | }, 154 | { 155 | "cell_type": "markdown", 156 | "metadata": {}, 157 | "source": [ 158 | "### Problem 4\n", 159 | "Explain a use case for a generator using a yield statement where you would not want to use a normal function with a return statement.\n", 160 | "\n", 161 | "**If the output has the potential of taking up a large amount of memory and you only intend to iterate through it, you would want to use a generator. (Multiple answers are acceptable here!)**" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "### Extra Credit!\n", 169 | "Can you explain what *gencomp* is in the code below? (Note: We never covered this in lecture!)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 7, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "4\n", 182 | "5\n" 183 | ] 184 | } 185 | ], 186 | "source": [ 187 | "my_list = [1,2,3,4,5]\n", 188 | "\n", 189 | "gencomp = (item for item in my_list if item > 3)\n", 190 | "\n", 191 | "for item in gencomp:\n", 192 | " print(item)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "metadata": {}, 198 | "source": [ 199 | "Hint: Google *generator comprehension*!\n", 200 | "\n", 201 | "# Great Job!" 202 | ] 203 | } 204 | ], 205 | "metadata": { 206 | "kernelspec": { 207 | "display_name": "Python 3", 208 | "language": "python", 209 | "name": "python3" 210 | }, 211 | "language_info": { 212 | "codemirror_mode": { 213 | "name": "ipython", 214 | "version": 3 215 | }, 216 | "file_extension": ".py", 217 | "mimetype": "text/x-python", 218 | "name": "python", 219 | "nbconvert_exporter": "python", 220 | "pygments_lexer": "ipython3", 221 | "version": "3.6.2" 222 | } 223 | }, 224 | "nbformat": 4, 225 | "nbformat_minor": 1 226 | } 227 | -------------------------------------------------------------------------------- /11-Python Generators/02-Iterators and Generators Homework.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Iterators and Generators Homework \n", 8 | "\n", 9 | "### Problem 1\n", 10 | "\n", 11 | "Create a generator that generates the squares of numbers up to some number N." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "def gensquares(N):\n", 21 | "\n", 22 | " pass" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 2, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "0\n", 35 | "1\n", 36 | "4\n", 37 | "9\n", 38 | "16\n", 39 | "25\n", 40 | "36\n", 41 | "49\n", 42 | "64\n", 43 | "81\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "for x in gensquares(10):\n", 49 | " print(x)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "### Problem 2\n", 57 | "\n", 58 | "Create a generator that yields \"n\" random numbers between a low and high number (that are inputs).
Note: Use the random library. For example:" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 3, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "data": { 68 | "text/plain": [ 69 | "9" 70 | ] 71 | }, 72 | "execution_count": 3, 73 | "metadata": {}, 74 | "output_type": "execute_result" 75 | } 76 | ], 77 | "source": [ 78 | "import random\n", 79 | "\n", 80 | "random.randint(1,10)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 4, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "def rand_num(low,high,n):\n", 90 | "\n", 91 | " pass" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 5, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "6\n", 104 | "1\n", 105 | "10\n", 106 | "5\n", 107 | "8\n", 108 | "2\n", 109 | "8\n", 110 | "5\n", 111 | "4\n", 112 | "5\n", 113 | "1\n", 114 | "4\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "for num in rand_num(1,10,12):\n", 120 | " print(num)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "### Problem 3\n", 128 | "\n", 129 | "Use the iter() function to convert the string below into an iterator:\n" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "s = 'hello'\n", 139 | "\n", 140 | "#code here" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "### Problem 4\n", 148 | "Explain a use case for a generator using a yield statement where you would not want to use a normal function with a return statement.





\n", 149 | "\n" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "### Extra Credit!\n", 157 | "Can you explain what *gencomp* is in the code below? (Note: We never covered this in lecture! You will have to do some Googling/Stack Overflowing!)" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 6, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "4\n", 170 | "5\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "my_list = [1,2,3,4,5]\n", 176 | "\n", 177 | "gencomp = (item for item in my_list if item > 3)\n", 178 | "\n", 179 | "for item in gencomp:\n", 180 | " print(item)" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "Hint: Google *generator comprehension*!\n", 188 | "\n", 189 | "# Great Job!" 190 | ] 191 | } 192 | ], 193 | "metadata": { 194 | "kernelspec": { 195 | "display_name": "Python 3", 196 | "language": "python", 197 | "name": "python3" 198 | }, 199 | "language_info": { 200 | "codemirror_mode": { 201 | "name": "ipython", 202 | "version": 3 203 | }, 204 | "file_extension": ".py", 205 | "mimetype": "text/x-python", 206 | "name": "python", 207 | "nbconvert_exporter": "python", 208 | "pygments_lexer": "ipython3", 209 | "version": "3.6.2" 210 | } 211 | }, 212 | "nbformat": 4, 213 | "nbformat_minor": 1 214 | } 215 | -------------------------------------------------------------------------------- /11-Python Generators/03-Iterators and Generators Homework - Solution.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Iterators and Generators Homework - Solution\n", 8 | "\n", 9 | "### Problem 1\n", 10 | "\n", 11 | "Create a generator that generates the squares of numbers up to some number N." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "def gensquares(N):\n", 21 | " for i in range(N):\n", 22 | " yield i**2" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 2, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "0\n", 35 | "1\n", 36 | "4\n", 37 | "9\n", 38 | "16\n", 39 | "25\n", 40 | "36\n", 41 | "49\n", 42 | "64\n", 43 | "81\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "for x in gensquares(10):\n", 49 | " print(x)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "### Problem 2\n", 57 | "\n", 58 | "Create a generator that yields \"n\" random numbers between a low and high number (that are inputs).
Note: Use the random library. For example:" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 3, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "data": { 68 | "text/plain": [ 69 | "3" 70 | ] 71 | }, 72 | "execution_count": 3, 73 | "metadata": {}, 74 | "output_type": "execute_result" 75 | } 76 | ], 77 | "source": [ 78 | "import random\n", 79 | "\n", 80 | "random.randint(1,10)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 4, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "def rand_num(low,high,n):\n", 90 | " \n", 91 | " for i in range(n):\n", 92 | " yield random.randint(low, high)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 5, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "3\n", 105 | "9\n", 106 | "6\n", 107 | "10\n", 108 | "8\n", 109 | "4\n", 110 | "5\n", 111 | "5\n", 112 | "5\n", 113 | "3\n", 114 | "5\n", 115 | "8\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "for num in rand_num(1,10,12):\n", 121 | " print(num)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "### Problem 3\n", 129 | "\n", 130 | "Use the iter() function to convert the string below into an iterator:\n" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 6, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "h\n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "s = 'hello'\n", 148 | "\n", 149 | "s = iter(s)\n", 150 | "\n", 151 | "print(next(s))" 152 | ] 153 | }, 154 | { 155 | "cell_type": "markdown", 156 | "metadata": {}, 157 | "source": [ 158 | "### Problem 4\n", 159 | "Explain a use case for a generator using a yield statement where you would not want to use a normal function with a return statement.\n", 160 | "\n", 161 | "**If the output has the potential of taking up a large amount of memory and you only intend to iterate through it, you would want to use a generator. (Multiple answers are acceptable here!)**" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "### Extra Credit!\n", 169 | "Can you explain what *gencomp* is in the code below? (Note: We never covered this in lecture!)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 7, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "4\n", 182 | "5\n" 183 | ] 184 | } 185 | ], 186 | "source": [ 187 | "my_list = [1,2,3,4,5]\n", 188 | "\n", 189 | "gencomp = (item for item in my_list if item > 3)\n", 190 | "\n", 191 | "for item in gencomp:\n", 192 | " print(item)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "metadata": {}, 198 | "source": [ 199 | "Hint: Google *generator comprehension*!\n", 200 | "\n", 201 | "# Great Job!" 202 | ] 203 | } 204 | ], 205 | "metadata": { 206 | "kernelspec": { 207 | "display_name": "Python 3", 208 | "language": "python", 209 | "name": "python3" 210 | }, 211 | "language_info": { 212 | "codemirror_mode": { 213 | "name": "ipython", 214 | "version": 3 215 | }, 216 | "file_extension": ".py", 217 | "mimetype": "text/x-python", 218 | "name": "python", 219 | "nbconvert_exporter": "python", 220 | "pygments_lexer": "ipython3", 221 | "version": "3.6.2" 222 | } 223 | }, 224 | "nbformat": 4, 225 | "nbformat_minor": 1 226 | } 227 | -------------------------------------------------------------------------------- /12-Final Capstone Python Project/.ipynb_checkpoints/01-Final Capstone Project-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true 7 | }, 8 | "source": [ 9 | "# Final Capstone Projects\n", 10 | "\n", 11 | "Please refer to the [**Final Capstone Projects**](http://nbviewer.jupyter.org/github/jmportilla/Complete-Python-Bootcamp/tree/master/Final%20Capstone%20Projects/) folder to get all the info on final capstone project ideas and possible solutions!" 12 | ] 13 | } 14 | ], 15 | "metadata": { 16 | "kernelspec": { 17 | "display_name": "Python 3", 18 | "language": "python", 19 | "name": "python3" 20 | }, 21 | "language_info": { 22 | "codemirror_mode": { 23 | "name": "ipython", 24 | "version": 3 25 | }, 26 | "file_extension": ".py", 27 | "mimetype": "text/x-python", 28 | "name": "python", 29 | "nbconvert_exporter": "python", 30 | "pygments_lexer": "ipython3", 31 | "version": "3.6.2" 32 | } 33 | }, 34 | "nbformat": 4, 35 | "nbformat_minor": 1 36 | } 37 | -------------------------------------------------------------------------------- /12-Final Capstone Python Project/01-Final Capstone Project.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true 7 | }, 8 | "source": [ 9 | "# Final Capstone Projects\n", 10 | "\n", 11 | "Please refer to the [**Final Capstone Projects**](http://nbviewer.jupyter.org/github/jmportilla/Complete-Python-Bootcamp/tree/master/Final%20Capstone%20Projects/) folder to get all the info on final capstone project ideas and possible solutions!" 12 | ] 13 | } 14 | ], 15 | "metadata": { 16 | "kernelspec": { 17 | "display_name": "Python 3", 18 | "language": "python", 19 | "name": "python3" 20 | }, 21 | "language_info": { 22 | "codemirror_mode": { 23 | "name": "ipython", 24 | "version": 3 25 | }, 26 | "file_extension": ".py", 27 | "mimetype": "text/x-python", 28 | "name": "python", 29 | "nbconvert_exporter": "python", 30 | "pygments_lexer": "ipython3", 31 | "version": "3.6.2" 32 | } 33 | }, 34 | "nbformat": 4, 35 | "nbformat_minor": 1 36 | } 37 | -------------------------------------------------------------------------------- /13-Advanced Python Modules/.ipynb_checkpoints/03-Python Debugger (pdb)-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Debugger\n", 8 | "\n", 9 | "You've probably used a variety of print statements to try to find errors in your code. A better way of doing this is by using Python's built-in debugger module (pdb). The pdb module implements an interactive debugging environment for Python programs. It includes features to let you pause your program, look at the values of variables, and watch program execution step-by-step, so you can understand what your program actually does and find bugs in the logic.\n", 10 | "\n", 11 | "This is a bit difficult to show since it requires creating an error on purpose, but hopefully this simple example illustrates the power of the pdb module.
*Note: Keep in mind it would be pretty unusual to use pdb in an iPython Notebook setting.*\n", 12 | "\n", 13 | "___\n", 14 | "Here we will create an error on purpose, trying to add a list to an integer" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "5\n" 27 | ] 28 | }, 29 | { 30 | "ename": "TypeError", 31 | "evalue": "unsupported operand type(s) for +: 'int' and 'list'", 32 | "output_type": "error", 33 | "traceback": [ 34 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 35 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 36 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mz\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mresult2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 37 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'list'" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "x = [1,3,4]\n", 43 | "y = 2\n", 44 | "z = 3\n", 45 | "\n", 46 | "result = y + z\n", 47 | "print(result)\n", 48 | "result2 = y+x\n", 49 | "print(result2)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "Hmmm, looks like we get an error! Let's implement a set_trace() using the pdb module. This will allow us to basically pause the code at the point of the trace and check if anything is wrong." 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "import pdb\n", 66 | "\n", 67 | "x = [1,3,4]\n", 68 | "y = 2\n", 69 | "z = 3\n", 70 | "\n", 71 | "result = y + z\n", 72 | "print(result)\n", 73 | "\n", 74 | "# Set a trace using Python Debugger\n", 75 | "pdb.set_trace()\n", 76 | "\n", 77 | "result2 = y+x\n", 78 | "print(result2)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "Great! Now we could check what the various variables were and check for errors. You can use 'q' to quit the debugger. For more information on general debugging techniques and more methods, check out the official documentation:\n", 86 | "https://docs.python.org/3/library/pdb.html" 87 | ] 88 | } 89 | ], 90 | "metadata": { 91 | "kernelspec": { 92 | "display_name": "Python 3", 93 | "language": "python", 94 | "name": "python3" 95 | }, 96 | "language_info": { 97 | "codemirror_mode": { 98 | "name": "ipython", 99 | "version": 3 100 | }, 101 | "file_extension": ".py", 102 | "mimetype": "text/x-python", 103 | "name": "python", 104 | "nbconvert_exporter": "python", 105 | "pygments_lexer": "ipython3", 106 | "version": "3.6.2" 107 | } 108 | }, 109 | "nbformat": 4, 110 | "nbformat_minor": 1 111 | } 112 | -------------------------------------------------------------------------------- /13-Advanced Python Modules/.ipynb_checkpoints/06-StringIO-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# StringIO Objects and the io Module\n", 8 | "\n", 9 | "Back in **Lecture 24 - Files** we opened files that exist outside of python, and streamed their contents into an in-memory file object. You can also create in-memory file-like objects within your program that Python treats the same way. Text data is stored in a StringIO object, while binary data would be stored in a BytesIO object. This object can then be used as input or output to most functions that would expect a standard file object.\n", 10 | "\n", 11 | "Let's investigate StringIO objects. The best way to show this is by example:" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "import io" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 2, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "# Arbitrary String\n", 30 | "message = 'This is just a normal string.'" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 3, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "# Use StringIO method to set as file object\n", 40 | "f = io.StringIO(message)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "Now we have an object *f* that we will be able to treat just like a file. For example:" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 4, 53 | "metadata": {}, 54 | "outputs": [ 55 | { 56 | "data": { 57 | "text/plain": [ 58 | "'This is just a normal string.'" 59 | ] 60 | }, 61 | "execution_count": 4, 62 | "metadata": {}, 63 | "output_type": "execute_result" 64 | } 65 | ], 66 | "source": [ 67 | "f.read()" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "We can also write to it:" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 5, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "data": { 84 | "text/plain": [ 85 | "40" 86 | ] 87 | }, 88 | "execution_count": 5, 89 | "metadata": {}, 90 | "output_type": "execute_result" 91 | } 92 | ], 93 | "source": [ 94 | "f.write(' Second line written to file like object')" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 6, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "0" 106 | ] 107 | }, 108 | "execution_count": 6, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "# Reset cursor just like you would a file\n", 115 | "f.seek(0)" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 7, 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "data": { 125 | "text/plain": [ 126 | "'This is just a normal string. Second line written to file like object'" 127 | ] 128 | }, 129 | "execution_count": 7, 130 | "metadata": {}, 131 | "output_type": "execute_result" 132 | } 133 | ], 134 | "source": [ 135 | "# Read again\n", 136 | "f.read()" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 8, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "# Close the object when contents are no longer needed\n", 146 | "f.close()" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "Great! Now you've seen how we can use StringIO to turn normal strings into in-memory file objects in our code. This kind of action has various use cases, especially in web scraping cases where you want to read some string you scraped as a file.\n", 154 | "\n", 155 | "For more info on StringIO check out the documentation: https://docs.python.org/3/library/io.html" 156 | ] 157 | } 158 | ], 159 | "metadata": { 160 | "kernelspec": { 161 | "display_name": "Python 3", 162 | "language": "python", 163 | "name": "python3" 164 | }, 165 | "language_info": { 166 | "codemirror_mode": { 167 | "name": "ipython", 168 | "version": 3 169 | }, 170 | "file_extension": ".py", 171 | "mimetype": "text/x-python", 172 | "name": "python", 173 | "nbconvert_exporter": "python", 174 | "pygments_lexer": "ipython3", 175 | "version": "3.6.2" 176 | } 177 | }, 178 | "nbformat": 4, 179 | "nbformat_minor": 1 180 | } 181 | -------------------------------------------------------------------------------- /13-Advanced Python Modules/03-Python Debugger (pdb).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Debugger\n", 8 | "\n", 9 | "You've probably used a variety of print statements to try to find errors in your code. A better way of doing this is by using Python's built-in debugger module (pdb). The pdb module implements an interactive debugging environment for Python programs. It includes features to let you pause your program, look at the values of variables, and watch program execution step-by-step, so you can understand what your program actually does and find bugs in the logic.\n", 10 | "\n", 11 | "This is a bit difficult to show since it requires creating an error on purpose, but hopefully this simple example illustrates the power of the pdb module.
*Note: Keep in mind it would be pretty unusual to use pdb in an iPython Notebook setting.*\n", 12 | "\n", 13 | "___\n", 14 | "Here we will create an error on purpose, trying to add a list to an integer" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "5\n" 27 | ] 28 | }, 29 | { 30 | "ename": "TypeError", 31 | "evalue": "unsupported operand type(s) for +: 'int' and 'list'", 32 | "output_type": "error", 33 | "traceback": [ 34 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 35 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 36 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mz\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mresult2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 37 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'list'" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "x = [1,3,4]\n", 43 | "y = 2\n", 44 | "z = 3\n", 45 | "\n", 46 | "result = y + z\n", 47 | "print(result)\n", 48 | "result2 = y+x\n", 49 | "print(result2)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "Hmmm, looks like we get an error! Let's implement a set_trace() using the pdb module. This will allow us to basically pause the code at the point of the trace and check if anything is wrong." 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "import pdb\n", 66 | "\n", 67 | "x = [1,3,4]\n", 68 | "y = 2\n", 69 | "z = 3\n", 70 | "\n", 71 | "result = y + z\n", 72 | "print(result)\n", 73 | "\n", 74 | "# Set a trace using Python Debugger\n", 75 | "pdb.set_trace()\n", 76 | "\n", 77 | "result2 = y+x\n", 78 | "print(result2)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "Great! Now we could check what the various variables were and check for errors. You can use 'q' to quit the debugger. For more information on general debugging techniques and more methods, check out the official documentation:\n", 86 | "https://docs.python.org/3/library/pdb.html" 87 | ] 88 | } 89 | ], 90 | "metadata": { 91 | "kernelspec": { 92 | "display_name": "Python 3", 93 | "language": "python", 94 | "name": "python3" 95 | }, 96 | "language_info": { 97 | "codemirror_mode": { 98 | "name": "ipython", 99 | "version": 3 100 | }, 101 | "file_extension": ".py", 102 | "mimetype": "text/x-python", 103 | "name": "python", 104 | "nbconvert_exporter": "python", 105 | "pygments_lexer": "ipython3", 106 | "version": "3.6.2" 107 | } 108 | }, 109 | "nbformat": 4, 110 | "nbformat_minor": 1 111 | } 112 | -------------------------------------------------------------------------------- /13-Advanced Python Modules/06-StringIO.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# StringIO Objects and the io Module\n", 8 | "\n", 9 | "Back in **Lecture 24 - Files** we opened files that exist outside of python, and streamed their contents into an in-memory file object. You can also create in-memory file-like objects within your program that Python treats the same way. Text data is stored in a StringIO object, while binary data would be stored in a BytesIO object. This object can then be used as input or output to most functions that would expect a standard file object.\n", 10 | "\n", 11 | "Let's investigate StringIO objects. The best way to show this is by example:" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "import io" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 2, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "# Arbitrary String\n", 30 | "message = 'This is just a normal string.'" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 3, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "# Use StringIO method to set as file object\n", 40 | "f = io.StringIO(message)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "Now we have an object *f* that we will be able to treat just like a file. For example:" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 4, 53 | "metadata": {}, 54 | "outputs": [ 55 | { 56 | "data": { 57 | "text/plain": [ 58 | "'This is just a normal string.'" 59 | ] 60 | }, 61 | "execution_count": 4, 62 | "metadata": {}, 63 | "output_type": "execute_result" 64 | } 65 | ], 66 | "source": [ 67 | "f.read()" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "We can also write to it:" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 5, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "data": { 84 | "text/plain": [ 85 | "40" 86 | ] 87 | }, 88 | "execution_count": 5, 89 | "metadata": {}, 90 | "output_type": "execute_result" 91 | } 92 | ], 93 | "source": [ 94 | "f.write(' Second line written to file like object')" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 6, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "0" 106 | ] 107 | }, 108 | "execution_count": 6, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "# Reset cursor just like you would a file\n", 115 | "f.seek(0)" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 7, 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "data": { 125 | "text/plain": [ 126 | "'This is just a normal string. Second line written to file like object'" 127 | ] 128 | }, 129 | "execution_count": 7, 130 | "metadata": {}, 131 | "output_type": "execute_result" 132 | } 133 | ], 134 | "source": [ 135 | "# Read again\n", 136 | "f.read()" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 8, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "# Close the object when contents are no longer needed\n", 146 | "f.close()" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "Great! Now you've seen how we can use StringIO to turn normal strings into in-memory file objects in our code. This kind of action has various use cases, especially in web scraping cases where you want to read some string you scraped as a file.\n", 154 | "\n", 155 | "For more info on StringIO check out the documentation: https://docs.python.org/3/library/io.html" 156 | ] 157 | } 158 | ], 159 | "metadata": { 160 | "kernelspec": { 161 | "display_name": "Python 3", 162 | "language": "python", 163 | "name": "python3" 164 | }, 165 | "language_info": { 166 | "codemirror_mode": { 167 | "name": "ipython", 168 | "version": 3 169 | }, 170 | "file_extension": ".py", 171 | "mimetype": "text/x-python", 172 | "name": "python", 173 | "nbconvert_exporter": "python", 174 | "pygments_lexer": "ipython3", 175 | "version": "3.6.2" 176 | } 177 | }, 178 | "nbformat": 4, 179 | "nbformat_minor": 1 180 | } 181 | -------------------------------------------------------------------------------- /14-Advanced Python Objects and Data Structures/.ipynb_checkpoints/06-Advanced Python Objects Test-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Advanced Python Objects Test" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Advanced Numbers\n", 15 | "\n", 16 | "**Problem 1: Convert 1024 to binary and hexadecimal representation**" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "**Problem 2: Round 5.23222 to two decimal places**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Advanced Strings\n", 45 | "**Problem 3: Check if every letter in the string s is lower case**" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "s = 'hello how are you Mary, are you feeling okay?'\n", 55 | "\n" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "**Problem 4: How many times does the letter 'w' show up in the string below?**" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "s = 'twywywtwywbwhsjhwuwshshwuwwwjdjdid'\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "## Advanced Sets\n", 79 | "**Problem 5: Find the elements in set1 that are not in set2:**" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "set1 = {2,3,1,5,6,8}\n", 89 | "set2 = {3,1,7,5,6,8}\n", 90 | "\n" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "**Problem 6: Find all elements that are in either set:**" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": {}, 110 | "source": [ 111 | "## Advanced Dictionaries\n", 112 | "\n", 113 | "**Problem 7: Create this dictionary:\n", 114 | "{0: 0, 1: 1, 2: 8, 3: 27, 4: 64}\n", 115 | " using a dictionary comprehension.**" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "## Advanced Lists\n", 130 | "\n", 131 | "**Problem 8: Reverse the list below:**" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "list1 = [1,2,3,4]\n" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "**Problem 9: Sort the list below:**" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "list2 = [3,4,2,5,1]\n" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "# Great Job!" 164 | ] 165 | } 166 | ], 167 | "metadata": { 168 | "kernelspec": { 169 | "display_name": "Python 3", 170 | "language": "python", 171 | "name": "python3" 172 | }, 173 | "language_info": { 174 | "codemirror_mode": { 175 | "name": "ipython", 176 | "version": 3 177 | }, 178 | "file_extension": ".py", 179 | "mimetype": "text/x-python", 180 | "name": "python", 181 | "nbconvert_exporter": "python", 182 | "pygments_lexer": "ipython3", 183 | "version": "3.6.2" 184 | } 185 | }, 186 | "nbformat": 4, 187 | "nbformat_minor": 1 188 | } 189 | -------------------------------------------------------------------------------- /14-Advanced Python Objects and Data Structures/06-Advanced Python Objects Test.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Advanced Python Objects Test" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Advanced Numbers\n", 15 | "\n", 16 | "**Problem 1: Convert 1024 to binary and hexadecimal representation**" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "**Problem 2: Round 5.23222 to two decimal places**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Advanced Strings\n", 45 | "**Problem 3: Check if every letter in the string s is lower case**" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "s = 'hello how are you Mary, are you feeling okay?'\n", 55 | "\n" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "**Problem 4: How many times does the letter 'w' show up in the string below?**" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "s = 'twywywtwywbwhsjhwuwshshwuwwwjdjdid'\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "## Advanced Sets\n", 79 | "**Problem 5: Find the elements in set1 that are not in set2:**" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "set1 = {2,3,1,5,6,8}\n", 89 | "set2 = {3,1,7,5,6,8}\n", 90 | "\n" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "**Problem 6: Find all elements that are in either set:**" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": {}, 110 | "source": [ 111 | "## Advanced Dictionaries\n", 112 | "\n", 113 | "**Problem 7: Create this dictionary:\n", 114 | "{0: 0, 1: 1, 2: 8, 3: 27, 4: 64}\n", 115 | " using a dictionary comprehension.**" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "## Advanced Lists\n", 130 | "\n", 131 | "**Problem 8: Reverse the list below:**" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "list1 = [1,2,3,4]\n" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "**Problem 9: Sort the list below:**" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "list2 = [3,4,2,5,1]\n" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "# Great Job!" 164 | ] 165 | } 166 | ], 167 | "metadata": { 168 | "kernelspec": { 169 | "display_name": "Python 3", 170 | "language": "python", 171 | "name": "python3" 172 | }, 173 | "language_info": { 174 | "codemirror_mode": { 175 | "name": "ipython", 176 | "version": 3 177 | }, 178 | "file_extension": ".py", 179 | "mimetype": "text/x-python", 180 | "name": "python", 181 | "nbconvert_exporter": "python", 182 | "pygments_lexer": "ipython3", 183 | "version": "3.6.2" 184 | } 185 | }, 186 | "nbformat": 4, 187 | "nbformat_minor": 1 188 | } 189 | -------------------------------------------------------------------------------- /16-Bonus Material - Introduction to GUIs/.ipynb_checkpoints/08-Advanced Widget Styling with Layout-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Advanced Widget Styling with Layout\n", 8 | "\n", 9 | "This notebook expands on the **Widget Styling** lecture by describing the various HTML and CSS adjustments that can be made through the `layout` attribute." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## The `layout` attribute\n", 17 | "Jupyter interactive widgets have a `layout` attribute exposing a number of CSS properties that impact how widgets are laid out.\n", 18 | "\n", 19 | "### Exposed CSS properties\n", 20 | "
The following properties map to the values of the CSS properties of the same name (underscores being replaced with dashes), applied to the top DOM elements of the corresponding widget.
\n", 21 | "\n", 22 | "#### Sizes\n", 23 | "* `height`\n", 24 | "* `width`\n", 25 | "* `max_height`\n", 26 | "* `max_width`\n", 27 | "* `min_height`\n", 28 | "* `min_width`\n", 29 | "\n", 30 | "#### Display\n", 31 | "* `visibility`\n", 32 | "* `display`\n", 33 | "* `overflow`\n", 34 | "* `overflow_x`\n", 35 | "* `overflow_y`\n", 36 | "\n", 37 | "#### Box model\n", 38 | "* `border`\n", 39 | "* `margin`\n", 40 | "* `padding`\n", 41 | "\n", 42 | "#### Positioning\n", 43 | "* `top`\n", 44 | "* `left`\n", 45 | "* `bottom`\n", 46 | "* `right`\n", 47 | "\n", 48 | "#### Flexbox\n", 49 | "* `order`\n", 50 | "* `flex_flow`\n", 51 | "* `align_items`\n", 52 | "* `flex`\n", 53 | "* `align_self`\n", 54 | "* `align_content`\n", 55 | "* `justify_content`\n", 56 | "\n", 57 | "### Shorthand CSS properties\n", 58 | "\n", 59 | "You may have noticed that certain CSS properties such as `margin-[top/right/bottom/left]` seem to be missing. The same holds for `padding-[top/right/bottom/left]` etc.\n", 60 | "\n", 61 | "In fact, you can atomically specify `[top/right/bottom/left]` margins via the `margin` attribute alone by passing the string `'100px 150px 100px 80px'` for a respectively `top`, `right`, `bottom` and `left` margins of `100`, `150`, `100` and `80` pixels.\n", 62 | "\n", 63 | "Similarly, the `flex` attribute can hold values for `flex-grow`, `flex-shrink` and `flex-basis`. The `border` attribute is a shorthand property for `border-width`, `border-style (required)`, and `border-color`." 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 19, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "import ipywidgets as widgets\n", 73 | "from IPython.display import display" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "# Conclusion\n", 81 | "\n", 82 | "You should now have an understanding of how to style widgets!" 83 | ] 84 | } 85 | ], 86 | "metadata": { 87 | "cell_tags": [ 88 | [ 89 | "", 90 | null 91 | ] 92 | ], 93 | "kernelspec": { 94 | "display_name": "Python 3", 95 | "language": "python", 96 | "name": "python3" 97 | }, 98 | "language_info": { 99 | "codemirror_mode": { 100 | "name": "ipython", 101 | "version": 3 102 | }, 103 | "file_extension": ".py", 104 | "mimetype": "text/x-python", 105 | "name": "python", 106 | "nbconvert_exporter": "python", 107 | "pygments_lexer": "ipython3", 108 | "version": "3.6.2" 109 | } 110 | }, 111 | "nbformat": 4, 112 | "nbformat_minor": 1 113 | } 114 | -------------------------------------------------------------------------------- /16-Bonus Material - Introduction to GUIs/08-Advanced Widget Styling with Layout.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Advanced Widget Styling with Layout\n", 8 | "\n", 9 | "This notebook expands on the **Widget Styling** lecture by describing the various HTML and CSS adjustments that can be made through the `layout` attribute." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## The `layout` attribute\n", 17 | "Jupyter interactive widgets have a `layout` attribute exposing a number of CSS properties that impact how widgets are laid out.\n", 18 | "\n", 19 | "### Exposed CSS properties\n", 20 | "
The following properties map to the values of the CSS properties of the same name (underscores being replaced with dashes), applied to the top DOM elements of the corresponding widget.
\n", 21 | "\n", 22 | "#### Sizes\n", 23 | "* `height`\n", 24 | "* `width`\n", 25 | "* `max_height`\n", 26 | "* `max_width`\n", 27 | "* `min_height`\n", 28 | "* `min_width`\n", 29 | "\n", 30 | "#### Display\n", 31 | "* `visibility`\n", 32 | "* `display`\n", 33 | "* `overflow`\n", 34 | "* `overflow_x`\n", 35 | "* `overflow_y`\n", 36 | "\n", 37 | "#### Box model\n", 38 | "* `border`\n", 39 | "* `margin`\n", 40 | "* `padding`\n", 41 | "\n", 42 | "#### Positioning\n", 43 | "* `top`\n", 44 | "* `left`\n", 45 | "* `bottom`\n", 46 | "* `right`\n", 47 | "\n", 48 | "#### Flexbox\n", 49 | "* `order`\n", 50 | "* `flex_flow`\n", 51 | "* `align_items`\n", 52 | "* `flex`\n", 53 | "* `align_self`\n", 54 | "* `align_content`\n", 55 | "* `justify_content`\n", 56 | "\n", 57 | "### Shorthand CSS properties\n", 58 | "\n", 59 | "You may have noticed that certain CSS properties such as `margin-[top/right/bottom/left]` seem to be missing. The same holds for `padding-[top/right/bottom/left]` etc.\n", 60 | "\n", 61 | "In fact, you can atomically specify `[top/right/bottom/left]` margins via the `margin` attribute alone by passing the string `'100px 150px 100px 80px'` for a respectively `top`, `right`, `bottom` and `left` margins of `100`, `150`, `100` and `80` pixels.\n", 62 | "\n", 63 | "Similarly, the `flex` attribute can hold values for `flex-grow`, `flex-shrink` and `flex-basis`. The `border` attribute is a shorthand property for `border-width`, `border-style (required)`, and `border-color`." 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 19, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "import ipywidgets as widgets\n", 73 | "from IPython.display import display" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "# Conclusion\n", 81 | "\n", 82 | "You should now have an understanding of how to style widgets!" 83 | ] 84 | } 85 | ], 86 | "metadata": { 87 | "cell_tags": [ 88 | [ 89 | "", 90 | null 91 | ] 92 | ], 93 | "kernelspec": { 94 | "display_name": "Python 3", 95 | "language": "python", 96 | "name": "python3" 97 | }, 98 | "language_info": { 99 | "codemirror_mode": { 100 | "name": "ipython", 101 | "version": 3 102 | }, 103 | "file_extension": ".py", 104 | "mimetype": "text/x-python", 105 | "name": "python", 106 | "nbconvert_exporter": "python", 107 | "pygments_lexer": "ipython3", 108 | "version": "3.6.2" 109 | } 110 | }, 111 | "nbformat": 4, 112 | "nbformat_minor": 1 113 | } 114 | -------------------------------------------------------------------------------- /17-Parallel Processing/test.py: -------------------------------------------------------------------------------- 1 | from random import random 2 | from multiprocessing import Pool 3 | import timeit 4 | 5 | def find_pi(n): 6 | """ 7 | Function to estimate the value of Pi 8 | """ 9 | inside=0 10 | 11 | for i in range(0,n): 12 | x=random() 13 | y=random() 14 | if (x*x+y*y)**(0.5)<=1: # if i falls inside the circle 15 | inside+=1 16 | 17 | pi=4*inside/n 18 | return pi 19 | 20 | if __name__ == '__main__': 21 | N = 10**7 # total iterations 22 | 23 | P = 1 # number of processes 24 | p = Pool(P) 25 | print(timeit.timeit(lambda: print(f'{sum(p.map(find_pi, [N//P]*P))/P:0.7f}'), number=10)) 26 | p.close() 27 | p.join() 28 | print(f'{N} total iterations with {P} processes') 29 | 30 | P = 5 # number of processes 31 | p = Pool(P) 32 | print(timeit.timeit(lambda: print(f'{sum(p.map(find_pi, [N//P]*P))/P:0.7f}'), number=10)) 33 | p.close() 34 | p.join() 35 | print(f'{N} total iterations with {P} processes\n') -------------------------------------------------------------------------------- /17-Parallel Processing/test2.py: -------------------------------------------------------------------------------- 1 | from random import random 2 | from multiprocessing import Pool 3 | import timeit 4 | import sys 5 | 6 | N = int(sys.argv[1]) # these arguments are passed in from the command line 7 | P = int(sys.argv[2]) 8 | 9 | def find_pi(n): 10 | """ 11 | Function to estimate the value of Pi 12 | """ 13 | inside=0 14 | 15 | for i in range(0,n): 16 | x=random() 17 | y=random() 18 | if (x*x+y*y)**(0.5)<=1: # if i falls inside the circle 19 | inside+=1 20 | 21 | pi=4*inside/n 22 | return pi 23 | 24 | if __name__ == '__main__': 25 | 26 | with Pool(P) as p: 27 | print(timeit.timeit(lambda: print(f'{sum(p.map(find_pi, [N//P]*P))/P:0.5f}'), number=10)) 28 | print(f'{N} total iterations with {P} processes') -------------------------------------------------------------------------------- /FAQ.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#FAQ\n", 8 | "This Notebook will be updated with Frequently Asked Questions for the Course." 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "**How do you see the hints? How do you see the DocStrings for functions? etc...**\n", 16 | "\n", 17 | "You can use Shift+Tab when you cursor is placed after an object or function for iPython to reveal the Docstring or more information." 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "**How do you auto-complete?**\n", 25 | "\n", 26 | "Use tab to autocomplete methods,objects, or functions. If there is more than one option available, multiple options appear." 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "collapsed": true 34 | }, 35 | "outputs": [], 36 | "source": [] 37 | } 38 | ], 39 | "metadata": { 40 | "kernelspec": { 41 | "display_name": "Python 2", 42 | "language": "python", 43 | "name": "python2" 44 | }, 45 | "language_info": { 46 | "codemirror_mode": { 47 | "name": "ipython", 48 | "version": 2 49 | }, 50 | "file_extension": ".py", 51 | "mimetype": "text/x-python", 52 | "name": "python", 53 | "nbconvert_exporter": "python", 54 | "pygments_lexer": "ipython2", 55 | "version": "2.7.10" 56 | } 57 | }, 58 | "nbformat": 4, 59 | "nbformat_minor": 0 60 | } 61 | -------------------------------------------------------------------------------- /Jupyter (iPython) Notebooks Guide.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Guide to Using Jupyter Notebooks\n", 8 | "In this lecture we will be going over the basics of the Jupyter (previously called iPython Notebooks).\n", 9 | "\n", 10 | "For a complete User Manual check out the [Bryn Mawr College Computer Science Guide](https://jupyter.brynmawr.edu/services/public/dblank/Jupyter%20Notebook%20Users%20Manual.ipynb).\n", 11 | "\n", 12 | "Most of the breakdown will actually occur in the presentation corresponding to this Notebook. So please refer to either the presentation or the full User Manual linked above." 13 | ] 14 | } 15 | ], 16 | "metadata": { 17 | "kernelspec": { 18 | "display_name": "Python 3", 19 | "language": "python", 20 | "name": "python3" 21 | }, 22 | "language_info": { 23 | "codemirror_mode": { 24 | "name": "ipython", 25 | "version": 3 26 | }, 27 | "file_extension": ".py", 28 | "mimetype": "text/x-python", 29 | "name": "python", 30 | "nbconvert_exporter": "python", 31 | "pygments_lexer": "ipython3", 32 | "version": "3.6.2" 33 | } 34 | }, 35 | "nbformat": 4, 36 | "nbformat_minor": 1 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Complete-Python-3-Bootcamp 2 | Course Files for Complete Python 3 Bootcamp Course on Udemy 3 | 4 | 5 | Get it now for 95% off with the link: 6 | https://www.udemy.com/complete-python-bootcamp/?couponCode=COMPLETE_GITHUB 7 | 8 | Thanks! 9 | --------------------------------------------------------------------------------