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;32mtry
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;32mwhile
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;32mtry
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;32mwhile
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).