|
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | | - "# Variables\n", |
| 7 | + "## 3. Variables\n", |
8 | 8 | "\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", |
10 | 10 | "\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", |
13 | 13 | "\n", |
14 | 14 | "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." |
15 | 15 | ] |
|
19 | 19 | "metadata": {}, |
20 | 20 | "source": [ |
21 | 21 | "#### 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." |
23 | 23 | ] |
24 | 24 | }, |
25 | 25 | { |
26 | 26 | "cell_type": "code", |
27 | | - "execution_count": null, |
| 27 | + "execution_count": 6, |
28 | 28 | "metadata": {}, |
29 | 29 | "outputs": [], |
30 | 30 | "source": [ |
|
36 | 36 | "metadata": {}, |
37 | 37 | "source": [ |
38 | 38 | "#### 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```." |
40 | 40 | ] |
41 | 41 | }, |
42 | 42 | { |
|
106 | 106 | "## Rules of Variables\n", |
107 | 107 | "\n", |
108 | 108 | "### 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", |
110 | 110 | "\n", |
111 | 111 | "#### Python variables can start with:\n", |
112 | 112 | "\n", |
|
117 | 117 | "**Numbers** ```0-9``` ,**letters**, and __underscores__. Example:\n", |
118 | 118 | "\n", |
119 | 119 | "```python\n", |
120 | | - "_this_is_a_variable_27 = \"whatever information\"```\n", |
| 120 | + "_this_is_a_variable_27 = \"Incubator Temperature Control\"```\n", |
121 | 121 | "\n", |
122 | 122 | "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." |
123 | 123 | ] |
|
138 | 138 | "metadata": {}, |
139 | 139 | "source": [ |
140 | 140 | "### 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)`." |
142 | 142 | ] |
143 | 143 | }, |
144 | 144 | { |
145 | 145 | "cell_type": "code", |
146 | | - "execution_count": null, |
| 146 | + "execution_count": 8, |
147 | 147 | "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 | + ], |
149 | 160 | "source": [ |
150 | 161 | "test = 3\n", |
151 | | - "test = \"cheese\"" |
| 162 | + "test = \"egg\"\n", |
| 163 | + "type(test)" |
152 | 164 | ] |
153 | 165 | }, |
154 | 166 | { |
155 | 167 | "cell_type": "markdown", |
156 | 168 | "metadata": {}, |
157 | 169 | "source": [ |
158 | 170 | "### 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\"```." |
160 | 172 | ] |
161 | 173 | }, |
162 | 174 | { |
|
175 | 187 | "metadata": {}, |
176 | 188 | "source": [ |
177 | 189 | "## 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", |
179 | 191 | "\n", |
180 | 192 | "(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.)" |
181 | 193 | ] |
182 | 194 | }, |
183 | 195 | { |
184 | 196 | "cell_type": "code", |
185 | | - "execution_count": null, |
| 197 | + "execution_count": 9, |
186 | 198 | "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 | + ], |
188 | 209 | "source": [ |
189 | 210 | "string = \n", |
190 | | - "interger = \n", |
| 211 | + "integer = \n", |
191 | 212 | "float1 = # \"float\" in code is already assigned so it's changed to something else, to avoid errors\n", |
192 | 213 | "boolean = " |
193 | 214 | ] |
|
196 | 217 | "cell_type": "markdown", |
197 | 218 | "metadata": {}, |
198 | 219 | "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", |
200 | 221 | "\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." |
202 | 223 | ] |
203 | 224 | }, |
204 | 225 | { |
|
207 | 228 | "metadata": {}, |
208 | 229 | "outputs": [], |
209 | 230 | "source": [ |
210 | | - "yourVariable = \n", |
| 231 | + "ChickenName = \n", |
211 | 232 | "x = True # This is a Boolean\n", |
212 | 233 | "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" |
214 | 235 | ] |
215 | 236 | } |
216 | 237 | ], |
|
230 | 251 | "name": "python", |
231 | 252 | "nbconvert_exporter": "python", |
232 | 253 | "pygments_lexer": "ipython3", |
233 | | - "version": "3.7.3" |
| 254 | + "version": "3.7.4" |
234 | 255 | } |
235 | 256 | }, |
236 | 257 | "nbformat": 4, |
|
0 commit comments