Skip to content

Commit 4221c52

Browse files
authored
Introduction to Python
1 parent 87c672f commit 4221c52

16 files changed

+963
-667
lines changed

00. Anaconda Install.ipynb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Anaconda Install\n",
8-
"If you're reading this from Jupyter running the downloaded files version off of github, you can skip this lesson. If you want to install Jupyter or learn some of its simple features, keep reading below.\n",
7+
"### Install Anaconda\n",
8+
"The first thing that you'll need is to install Anaconda and run the Jupyter notebook. [Download Anaconda to use Jupyter](https://www.anaconda.com/distribution/) or [watch a video on how to install it](https://youtu.be/LrMOrMb8-3s).\n",
99
"\n",
10-
"## [Download Anaconda to use Jupyter](https://docs.anaconda.com/anaconda/install/) or [watch a video on how to do it](https://youtu.be/LrMOrMb8-3s).\n",
11-
"\n",
12-
"Please use the two links above if you want to use the downloaded files, from [github](https://github.com/BaconBomber/BeginnersTCLab), but can't run Jupyter. Jupyter is a program run from [Anaconda](https://www.anaconda.com/).\n",
13-
"\n",
14-
"You can also use the code down below to run the video if you have a Python interpreter. The video is about Anaconda install and also a few things you can do with the many interpreters that Anaconda comes with. Examples are given for Jupyter and Spyder."
10+
"You can also use the code down below to show the video if you have a Python interpreter. The video is about how to install Anaconda and a few things you can do with Anaconda. Examples are with Jupyter and Spyder."
1511
]
1612
},
1713
{
@@ -34,7 +30,7 @@
3430
" "
3531
],
3632
"text/plain": [
37-
"<IPython.lib.display.YouTubeVideo at 0x2a520211470>"
33+
"<IPython.lib.display.YouTubeVideo at 0x1e2145efd48>"
3834
]
3935
},
4036
"execution_count": 1,
@@ -46,6 +42,13 @@
4642
"from IPython.display import YouTubeVideo\n",
4743
"YouTubeVideo('LrMOrMb8-3s')"
4844
]
45+
},
46+
{
47+
"cell_type": "markdown",
48+
"metadata": {},
49+
"source": [
50+
"There are [additional instructions on installing Python and managing modules](https://apmonitor.com/pdc/index.php/Main/InstallPython)."
51+
]
4952
}
5053
],
5154
"metadata": {
@@ -64,7 +67,7 @@
6467
"name": "python",
6568
"nbconvert_exporter": "python",
6669
"pygments_lexer": "ipython3",
67-
"version": "3.7.3"
70+
"version": "3.7.4"
6871
}
6972
},
7073
"nbformat": 4,

01. Overview.ipynb

Lines changed: 63 additions & 11 deletions
Large diffs are not rendered by default.

02. Debugging.ipynb

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,85 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Debugging\n",
7+
"## 2. Debugging\n",
88
"\n",
9-
"One of the biggest time consumers in programming is debugging, or mistakes in your programming. This is true for every language because the computer needs exact commands, which is very important for precise measurements for incubating. To limit this mistake, a couple of steps can limit the time you are just looking for mistakes, instead of just programming. \n",
9+
"One of the biggest time consuming parts of programming is debugging, or resolving mistakes in the program. This is true for every language because the computer needs exact commands, which is very important for precise measurements and control for incubating. A few steps can limit the time you are searching for mistakes, instead of completing the project. \n",
1010
"\n",
11-
"### Steps for more effective programming\n",
12-
"#### _First_\n",
13-
"You should start with understanding the big picture. It seems silly, but once you start going over the whole thing you find a lot of gaps. Do this in whichever way suits you best, we’ll leave it up to you. \n",
11+
"**Steps for more effective programming**\n",
1412
"\n",
15-
"For incubation, it would be understanding what you actually need to do for keeping an egg in good conditions.\n",
16-
"#### _Second_\n",
17-
"Start with outlining your code, writing in English what you want the code to do, then break it into more direct tasks. You can do this once you understand the basics of python, so you know what you are capable of programming and to make sure your programming isn't more complex than it needs to be.\n",
13+
"1. Start with understanding the big picture. It seems silly, but once you start going over the whole thing you find a lot of gaps. Do this in whichever way suits you best, we’ll leave it up to you. For the egg incubator, it would be understanding what you actually need to do to help an egg hatch.\n",
1814
"\n",
19-
"Something like setting the value of temperature to a certain number, instead of a complex equation to get the same number.\n",
20-
"#### _Third_\n",
21-
"Program the specific tasks and connect them together. The explained direct tasks make it significantly easier to program. It’s a lot harder to program something all in one go if the program is bigger. \n",
15+
"2. Start by outlining your code, writing **high-level instructions (pseudo-code)** what you want each section of the code to do. Break it into more specific tasks. You can do this even without understanding the basics of Python. Once you learn Python basics, you can translate these high level instructions into code. Organizing the outline helps to make sure your programming isn't more complex than it needs to be.\n",
2216
"\n",
23-
"This means programming something specific like how hard the heater should work, based on how low a temperature reading is.\n",
24-
"#### _Fourth_\n",
25-
"Test and fix problems. Basically debugging, but don’t only test the whole project all in one go. It’s much easier to find a problem if you test every once in a while, when you are programming smaller parts. A good way to do this is grab a specific piece of code, run it on a seperate file, and see if it does the job you want. \n",
17+
"3. Program the specific tasks and connect them together. Direct tasks make it significantly easier to program because the program is modular. It’s a lot harder to program something if the program is large and complex. For the incubator, this may be programming something specific like how hard the heater should work, based on a low temperature reading.\n",
2618
"\n",
27-
"An example would be fixing when the heater should stop working, so the egg doesn't go over temperature.\n",
19+
"4. Test and fix problems. This is basically debugging, but don’t only test the whole project all in one go. It’s much easier to find a problem if you test every once in a while, when you are programming smaller parts. A good way to do this is grab a specific piece of code, run it on a seperate file, and see if it does the job you want. An example would be fixing when the heater should stop working, so the egg doesn't go over temperature.\n",
2820
"\n",
29-
"(The better you follow these steps the less time you will have to spend fixing problems in your code for your incubators, or just python programs in general.)"
21+
"The better you follow these steps the less time you will have to spend fixing problems in your code for your incubator, or just Python programs in general.\n",
22+
"\n",
23+
"**Debugging Practice**\n",
24+
"\n",
25+
"Fix the errors in the following code cells. Use the error messages to help you locate the problems."
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 9,
31+
"metadata": {},
32+
"outputs": [
33+
{
34+
"ename": "SyntaxError",
35+
"evalue": "invalid syntax (<ipython-input-9-7d7d53e578fa>, line 1)",
36+
"output_type": "error",
37+
"traceback": [
38+
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-9-7d7d53e578fa>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m print('Program to Hatch an Egg) # hint: look for a missing ' character\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"print('Program to Hatch an Egg) # hint: look for a missing ' character"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": 8,
49+
"metadata": {},
50+
"outputs": [
51+
{
52+
"ename": "SyntaxError",
53+
"evalue": "invalid syntax (<ipython-input-8-afaacfd12f22>, line 1)",
54+
"output_type": "error",
55+
"traceback": [
56+
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-8-afaacfd12f22>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m target temperature = 37 # hint: variable names cannot have spaces\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
57+
]
58+
}
59+
],
60+
"source": [
61+
"target temperature = 37 # hint: variable names cannot have spaces"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": 7,
67+
"metadata": {},
68+
"outputs": [
69+
{
70+
"ename": "TypeError",
71+
"evalue": "unsupported operand type(s) for +: 'int' and 'str'",
72+
"output_type": "error",
73+
"traceback": [
74+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
75+
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
76+
"\u001b[1;32m<ipython-input-7-0c5f3e537629>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mtarget_temperature\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m37\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mdifference\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtarget_temperature\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mcurrent_temperature\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdifference\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m'degC'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
77+
"\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'"
78+
]
79+
}
80+
],
81+
"source": [
82+
"current_temperature = 30\n",
83+
"target_temperature = 37\n",
84+
"difference = target_temperature - current_temperature\n",
85+
"print(difference + 'degC') # hint: use str(difference) to make it a string"
3086
]
3187
}
3288
],
@@ -46,7 +102,7 @@
46102
"name": "python",
47103
"nbconvert_exporter": "python",
48104
"pygments_lexer": "ipython3",
49-
"version": "3.7.3"
105+
"version": "3.7.4"
50106
}
51107
},
52108
"nbformat": 4,

03. Variables.ipynb

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Variables\n",
7+
"## 3. Variables\n",
88
"\n",
9-
"Variables are something that stores information in python. For example, if you wanted to keep a set temperature for an egg, you would type ```egg = 99.5```. The first part tells what the variable will be called, and the value after the ```=``` tells what is being stored. \n",
9+
"Variables are something that stores information in python. For example, if you wanted to keep a set temperature for an egg, you would type ```egg = 37.5``` for °C or ```egg = 99.5``` for °F. The first part tells what the variable will be called, and the value after the ```=``` tells what is being stored. \n",
1010
"\n",
11-
"## Values in Variables\n",
12-
"There are many types of values but for now, we’ll just go through the basics. You can run the code, but in this case the computer won't tell you anything, because you're just storing values. \n",
11+
"**Values in Variables**\n",
12+
"There are many types of value types but for now, we’ll just go through the basics. You can run the code, but in this case the computer won't tell you anything, because it is only storing values. \n",
1313
"\n",
1414
"While you can run a program by clicking the run button towards the top of the screen, a better way to run cells individually is to click a cell, then hold ```Ctrl``` and press ```Enter```. Running this way means you're running one cell at a time, instead of all at once. Some Jupyter Notebooks also have the run button to the left of the program cell."
1515
]
@@ -19,12 +19,12 @@
1919
"metadata": {},
2020
"source": [
2121
"#### Integers\n",
22-
"Integers, or ```int```, are the value of a basic, whole number like ```9```. "
22+
"Integers, or ```int```, are the value of a basic, whole number like ```99```. You can use the function `int(99.5)` to convert a number to an integer `99` as it removes any numbers after the decimal."
2323
]
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": null,
27+
"execution_count": 6,
2828
"metadata": {},
2929
"outputs": [],
3030
"source": [
@@ -36,7 +36,7 @@
3636
"metadata": {},
3737
"source": [
3838
"#### Floats\n",
39-
"Floats, or ```float```, are basically the same thing, but with decimals like ```4.72```."
39+
"Floating point numbers, or ```float```, are basically the same thing, but with decimals like ```4.72```."
4040
]
4141
},
4242
{
@@ -106,7 +106,7 @@
106106
"## Rules of Variables\n",
107107
"\n",
108108
"### Variable Naming\n",
109-
"There are a couple of rules though because python still needs exact commands. In order to properly name a variable, it can only start with a __letters__ or an __underscore__. After the first character you can use __letters, __numbers__, and __underscores__. \n",
109+
"In order to properly name a variable, it can only start with a __letters__ or an __underscore__. After the first character you can use __letters, __numbers__, and __underscores__. \n",
110110
"\n",
111111
"#### Python variables can start with:\n",
112112
"\n",
@@ -117,7 +117,7 @@
117117
"**Numbers** ```0-9``` ,**letters**, and __underscores__. Example:\n",
118118
"\n",
119119
"```python\n",
120-
"_this_is_a_variable_27 = \"whatever information\"```\n",
120+
"_this_is_a_variable_27 = \"Incubator Temperature Control\"```\n",
121121
"\n",
122122
"If you want to check your understanding, run incorrect variables and then fix the variable names to whatever you want. Make sure the it follows naming rules."
123123
]
@@ -138,25 +138,37 @@
138138
"metadata": {},
139139
"source": [
140140
"### Variable Properties\n",
141-
"Variables can be assigned to something as you already know. If you assign them again later in the code it simply changes to that new assignment. For example, the code below would first use ```3``` for ```test```, but after would use ```cheese``` instead."
141+
"Variables can be assigned a value such as a string, integer, or float. If you assign them again later in the code it simply changes to that new assignment. For example, the code below would first use ```3``` for ```test```, but after would use ```egg``` instead. Unlike other programming languages, Python variables are mutable (can change type). You can see the variable type with `type(test)`."
142142
]
143143
},
144144
{
145145
"cell_type": "code",
146-
"execution_count": null,
146+
"execution_count": 8,
147147
"metadata": {},
148-
"outputs": [],
148+
"outputs": [
149+
{
150+
"data": {
151+
"text/plain": [
152+
"str"
153+
]
154+
},
155+
"execution_count": 8,
156+
"metadata": {},
157+
"output_type": "execute_result"
158+
}
159+
],
149160
"source": [
150161
"test = 3\n",
151-
"test = \"cheese\""
162+
"test = \"egg\"\n",
163+
"type(test)"
152164
]
153165
},
154166
{
155167
"cell_type": "markdown",
156168
"metadata": {},
157169
"source": [
158170
"### Variable Usage\n",
159-
"Variables can be used in math or when you are trying to show a result, which is very useful but they do have restrictions. Different types of value typically can't be combined, such as ```5 + \"degC\"```. This can sometimes be fixed if you need __5degC__ to be output. All you do is change the value type of ```5``` manually into a __string__, ```str(5) + \"degC\"```. But, you can't turn a __string__ into a __interger__ which makes sense, the letter _n_ for example doesn't have a number that goes with it."
171+
"Variables can be used in math or when you are trying to show a result, which is very useful but they do have restrictions. Different types of values typically can't be added together, such as ```5 + \"degC\"```. This can be fixed if you need __5degC__ to be output. Change the value type of ```5``` manually into a __string__, ```str(5) + \"degC\"```."
160172
]
161173
},
162174
{
@@ -175,19 +187,28 @@
175187
"metadata": {},
176188
"source": [
177189
"## Activity\n",
178-
"Make one variable for every variable type, string, interger, float, and boolean.\n",
190+
"Make one variable for every variable type, string, integer, float, and boolean.\n",
179191
"\n",
180192
"(The ```#``` symbol makes the text behind it a comment. Those words are just for discribing the program, they don't do anything to the code.)"
181193
]
182194
},
183195
{
184196
"cell_type": "code",
185-
"execution_count": null,
197+
"execution_count": 9,
186198
"metadata": {},
187-
"outputs": [],
199+
"outputs": [
200+
{
201+
"ename": "SyntaxError",
202+
"evalue": "invalid syntax (<ipython-input-9-480f02309b9f>, line 1)",
203+
"output_type": "error",
204+
"traceback": [
205+
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-9-480f02309b9f>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m string =\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
206+
]
207+
}
208+
],
188209
"source": [
189210
"string = \n",
190-
"interger = \n",
211+
"integer = \n",
191212
"float1 = # \"float\" in code is already assigned so it's changed to something else, to avoid errors\n",
192213
"boolean = "
193214
]
@@ -196,9 +217,9 @@
196217
"cell_type": "markdown",
197218
"metadata": {},
198219
"source": [
199-
"Try making your own variable to store a random piece of information, your siblings name, your age, whatever you like. Make sure to change the assignment name from ```yourVariable``` to what the information is about so you remember. \n",
220+
"Try making your own variable to store your chicken's name. Make sure to change the assignment name from ```yourVariable``` to what the information is about so you remember. \n",
200221
"\n",
201-
"Then combine the variables, ```x``` and ```y```, below by changing their types to __strings__. If you get stuck, the example just above changes ```interger``` 5 into a string. Use the same code on x and y."
222+
"Then combine the variables, ```x``` and ```y```, below by changing their types to __strings__. If you get stuck, the example just above changes ```integer``` 5 into a string. Use the same code on x and y."
202223
]
203224
},
204225
{
@@ -207,10 +228,10 @@
207228
"metadata": {},
208229
"outputs": [],
209230
"source": [
210-
"yourVariable = \n",
231+
"ChickenName = \n",
211232
"x = True # This is a Boolean\n",
212233
"y = 236.4 # This is a float\n",
213-
"combined = (x) + (y) # Make x and y strings"
234+
"combined = x + y # Make x and y strings"
214235
]
215236
}
216237
],
@@ -230,7 +251,7 @@
230251
"name": "python",
231252
"nbconvert_exporter": "python",
232253
"pygments_lexer": "ipython3",
233-
"version": "3.7.3"
254+
"version": "3.7.4"
234255
}
235256
},
236257
"nbformat": 4,

0 commit comments

Comments
 (0)