|
12 | 12 | "cell_type": "markdown",
|
13 | 13 | "metadata": {},
|
14 | 14 | "source": [
|
15 |
| - "## Printing to the screen (terminal)\n", |
| 15 | + "## Printing to the Screen (Terminal)\n", |
16 | 16 | "In Python, you can use the function `print()` to display things on the screen.\n",
|
17 | 17 | "Put the item to be printed inside the parentheses."
|
18 | 18 | ]
|
19 | 19 | },
|
20 | 20 | {
|
21 | 21 | "cell_type": "code",
|
22 | 22 | "execution_count": null,
|
23 |
| - "metadata": { |
24 |
| - "collapsed": true |
25 |
| - }, |
| 23 | + "metadata": {}, |
26 | 24 | "outputs": [],
|
27 | 25 | "source": [
|
28 | 26 | "print(2)"
|
|
38 | 36 | {
|
39 | 37 | "cell_type": "code",
|
40 | 38 | "execution_count": null,
|
41 |
| - "metadata": { |
42 |
| - "collapsed": true |
43 |
| - }, |
| 39 | + "metadata": {}, |
44 | 40 | "outputs": [],
|
45 | 41 | "source": [
|
46 | 42 | "print(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)"
|
|
56 | 52 | {
|
57 | 53 | "cell_type": "code",
|
58 | 54 | "execution_count": null,
|
59 |
| - "metadata": { |
60 |
| - "collapsed": true |
61 |
| - }, |
| 55 | + "metadata": {}, |
62 | 56 | "outputs": [],
|
63 | 57 | "source": [
|
64 | 58 | "print(\"This message will be printed\")"
|
|
80 | 74 | {
|
81 | 75 | "cell_type": "code",
|
82 | 76 | "execution_count": null,
|
83 |
| - "metadata": { |
84 |
| - "collapsed": true |
85 |
| - }, |
| 77 | + "metadata": {}, |
86 | 78 | "outputs": [],
|
87 | 79 | "source": [
|
88 | 80 | "a = 2\n",
|
|
91 | 83 | "print(\"2: b =\", b)\n",
|
92 | 84 | "a = a + 2\n",
|
93 | 85 | "print(\"3: a =\", a)\n",
|
94 |
| - "print(\"4: b =\", b)\n" |
| 86 | + "print(\"4: b =\", b)" |
95 | 87 | ]
|
96 | 88 | },
|
97 | 89 | {
|
|
123 | 115 | {
|
124 | 116 | "cell_type": "code",
|
125 | 117 | "execution_count": null,
|
126 |
| - "metadata": { |
127 |
| - "collapsed": true |
128 |
| - }, |
| 118 | + "metadata": {}, |
129 | 119 | "outputs": [],
|
130 | 120 | "source": [
|
131 | 121 | "VARIABLE_NAME_with_1_2_3 = 0"
|
|
143 | 133 | {
|
144 | 134 | "cell_type": "code",
|
145 | 135 | "execution_count": null,
|
146 |
| - "metadata": { |
147 |
| - "collapsed": true |
148 |
| - }, |
| 136 | + "metadata": {}, |
149 | 137 | "outputs": [],
|
150 | 138 | "source": [
|
151 | 139 | "pi = 3.14\n",
|
|
157 | 145 | "cell_type": "markdown",
|
158 | 146 | "metadata": {},
|
159 | 147 | "source": [
|
160 |
| - "## Variables as sticky notes\n", |
| 148 | + "### <span style=\"color:green\"> Exercise: Variable Names </span>\n", |
| 149 | + "\n", |
| 150 | + "Why does the code below yield an error? Fix the code such that the name is printed." |
| 151 | + ] |
| 152 | + }, |
| 153 | + { |
| 154 | + "cell_type": "code", |
| 155 | + "execution_count": null, |
| 156 | + "metadata": {}, |
| 157 | + "outputs": [], |
| 158 | + "source": [ |
| 159 | + "name = \"Arthur\"\n", |
| 160 | + "print(Name)" |
| 161 | + ] |
| 162 | + }, |
| 163 | + { |
| 164 | + "cell_type": "markdown", |
| 165 | + "metadata": {}, |
| 166 | + "source": [ |
| 167 | + "## Variables as Sticky Notes\n", |
161 | 168 | "\n",
|
162 | 169 | "Python variables are *independent* from each other.\n",
|
163 | 170 | "Let's define two variables. Alice is 20 years old, and her classmate Bob is the same age:"
|
|
166 | 173 | {
|
167 | 174 | "cell_type": "code",
|
168 | 175 | "execution_count": null,
|
169 |
| - "metadata": { |
170 |
| - "collapsed": true |
171 |
| - }, |
| 176 | + "metadata": {}, |
172 | 177 | "outputs": [],
|
173 | 178 | "source": [
|
174 | 179 | "alice_age = 20\n",
|
|
185 | 190 | {
|
186 | 191 | "cell_type": "code",
|
187 | 192 | "execution_count": null,
|
188 |
| - "metadata": { |
189 |
| - "collapsed": true |
190 |
| - }, |
| 193 | + "metadata": {}, |
191 | 194 | "outputs": [],
|
192 | 195 | "source": [
|
193 | 196 | "alice_age = 21\n",
|
|
210 | 213 | "cell_type": "markdown",
|
211 | 214 | "metadata": {},
|
212 | 215 | "source": [
|
213 |
| - "## Python as calculator \n", |
| 216 | + "## Python as a Calculator \n", |
214 | 217 | "You can do simple math like this:\n",
|
215 | 218 | "\n",
|
216 | 219 | "$\\Large{\\cdot}$ $a - b$ in Python : `a - b` \n",
|
|
225 | 228 | {
|
226 | 229 | "cell_type": "code",
|
227 | 230 | "execution_count": null,
|
228 |
| - "metadata": { |
229 |
| - "collapsed": true |
230 |
| - }, |
| 231 | + "metadata": {}, |
231 | 232 | "outputs": [],
|
232 | 233 | "source": [
|
233 | 234 | "a = 1\n",
|
|
244 | 245 | "cell_type": "markdown",
|
245 | 246 | "metadata": {},
|
246 | 247 | "source": [
|
247 |
| - "## Exercise: understanding variables\n", |
| 248 | + "### <span style=\"color:green\"> Exercise: Understanding Variables </span>\n", |
248 | 249 | "\n",
|
249 | 250 | "Go through the following lines of code step-by-step.\n",
|
250 | 251 | "What are the values of the different variables after each step?\n",
|
|
254 | 255 | {
|
255 | 256 | "cell_type": "code",
|
256 | 257 | "execution_count": null,
|
257 |
| - "metadata": { |
258 |
| - "collapsed": true |
259 |
| - }, |
| 258 | + "metadata": {}, |
260 | 259 | "outputs": [],
|
261 | 260 | "source": [
|
262 | 261 | "length = 100\n",
|
|
270 | 269 | "cell_type": "markdown",
|
271 | 270 | "metadata": {},
|
272 | 271 | "source": [
|
273 |
| - "## Exercise: using variables\n", |
| 272 | + "### <span style=\"color:green\"> Exercise: Using Variables </span>\n", |
274 | 273 | "\n",
|
275 | 274 | "Alice weighs 65 kg, and Bob weighs 70 kg.\n",
|
276 | 275 | "1. Create variables containing these data. Try to think of descriptive variable names.\n",
|
|
292 | 291 | "cell_type": "markdown",
|
293 | 292 | "metadata": {},
|
294 | 293 | "source": [
|
295 |
| - "### Integers (whole numbers)\n", |
| 294 | + "### Integers (Whole Numbers)\n", |
296 | 295 | "\n",
|
297 | 296 | "In Python a whole number is called an *integer*, but when programming we use the abbreviation `int`."
|
298 | 297 | ]
|
299 | 298 | },
|
300 | 299 | {
|
301 | 300 | "cell_type": "code",
|
302 | 301 | "execution_count": null,
|
303 |
| - "metadata": { |
304 |
| - "collapsed": true |
305 |
| - }, |
| 302 | + "metadata": {}, |
306 | 303 | "outputs": [],
|
307 | 304 | "source": [
|
308 | 305 | "print(type(2))"
|
|
312 | 309 | "cell_type": "markdown",
|
313 | 310 | "metadata": {},
|
314 | 311 | "source": [
|
315 |
| - "### Float (decimal numbers)\n", |
| 312 | + "### Float (Decimal Numbers)\n", |
316 | 313 | "\n",
|
317 | 314 | "A decimal number is called a `floating point number`, but when programming it is abbreviated `float`."
|
318 | 315 | ]
|
319 | 316 | },
|
320 | 317 | {
|
321 | 318 | "cell_type": "code",
|
322 | 319 | "execution_count": null,
|
323 |
| - "metadata": { |
324 |
| - "collapsed": true |
325 |
| - }, |
| 320 | + "metadata": {}, |
326 | 321 | "outputs": [],
|
327 | 322 | "source": [
|
328 | 323 | "print(type(1.2))"
|
|
332 | 327 | "cell_type": "markdown",
|
333 | 328 | "metadata": {},
|
334 | 329 | "source": [
|
335 |
| - "### String (text) \n", |
| 330 | + "### String (Text) \n", |
336 | 331 | "\n",
|
337 | 332 | "In Python, text is called *String*, abbreviated `str`. \n",
|
338 | 333 | "\n",
|
|
343 | 338 | {
|
344 | 339 | "cell_type": "code",
|
345 | 340 | "execution_count": null,
|
346 |
| - "metadata": { |
347 |
| - "collapsed": true |
348 |
| - }, |
| 341 | + "metadata": {}, |
349 | 342 | "outputs": [],
|
350 | 343 | "source": [
|
351 | 344 | "print(type(\"spam\"))"
|
|
364 | 357 | {
|
365 | 358 | "cell_type": "code",
|
366 | 359 | "execution_count": null,
|
367 |
| - "metadata": { |
368 |
| - "collapsed": true |
369 |
| - }, |
| 360 | + "metadata": {}, |
370 | 361 | "outputs": [],
|
371 | 362 | "source": [
|
372 | 363 | "print(spam)"
|
|
376 | 367 | "cell_type": "markdown",
|
377 | 368 | "metadata": {},
|
378 | 369 | "source": [
|
379 |
| - "### Exercise: datatypes\n", |
| 370 | + "### <span style=\"color:green\">Exercise: datatypes</span>\n", |
380 | 371 | "\n",
|
381 | 372 | "Can you change the variables below, so that all three contains the value 2, but with different datatypes?"
|
382 | 373 | ]
|
383 | 374 | },
|
384 | 375 | {
|
385 | 376 | "cell_type": "code",
|
386 | 377 | "execution_count": null,
|
387 |
| - "metadata": { |
388 |
| - "collapsed": true |
389 |
| - }, |
| 378 | + "metadata": {}, |
390 | 379 | "outputs": [],
|
391 | 380 | "source": [
|
392 | 381 | "int_2 = ?\n",
|
|
396 | 385 | {
|
397 | 386 | "cell_type": "code",
|
398 | 387 | "execution_count": null,
|
399 |
| - "metadata": { |
400 |
| - "collapsed": true |
401 |
| - }, |
| 388 | + "metadata": {}, |
402 | 389 | "outputs": [],
|
403 | 390 | "source": [
|
404 | 391 | "float_2 = ?\n",
|
|
408 | 395 | {
|
409 | 396 | "cell_type": "code",
|
410 | 397 | "execution_count": null,
|
411 |
| - "metadata": { |
412 |
| - "collapsed": true |
413 |
| - }, |
| 398 | + "metadata": {}, |
414 | 399 | "outputs": [],
|
415 | 400 | "source": [
|
416 | 401 | "str_2 = ?\n",
|
|
421 | 406 | "cell_type": "markdown",
|
422 | 407 | "metadata": {},
|
423 | 408 | "source": [
|
424 |
| - "## Importing libraries/modules\n", |
| 409 | + "## Importing Libraries/Modules\n", |
425 | 410 | "\n",
|
426 | 411 | "A module is a collection of functions that someone has written. A library is a collection of modules.\n",
|
427 | 412 | "There are innumerable python libraries available for performing diverse tasks.\n",
|
|
439 | 424 | {
|
440 | 425 | "cell_type": "code",
|
441 | 426 | "execution_count": null,
|
442 |
| - "metadata": { |
443 |
| - "collapsed": true |
444 |
| - }, |
| 427 | + "metadata": {}, |
445 | 428 | "outputs": [],
|
446 | 429 | "source": [
|
447 | 430 | "import math\n",
|
|
465 | 448 | {
|
466 | 449 | "cell_type": "code",
|
467 | 450 | "execution_count": null,
|
468 |
| - "metadata": { |
469 |
| - "collapsed": true |
470 |
| - }, |
| 451 | + "metadata": {}, |
471 | 452 | "outputs": [],
|
472 | 453 | "source": [
|
473 | 454 | "from math import pi, sin\n",
|
|
478 | 459 | "cell_type": "markdown",
|
479 | 460 | "metadata": {},
|
480 | 461 | "source": [
|
481 |
| - "## Commenting code\n", |
| 462 | + "## Commenting Code\n", |
482 | 463 | "\n",
|
483 | 464 | "Comments can make your code easier to understand. You can use a `#` character to start a single line comment. \n",
|
484 | 465 | "To write a comment consisting of multiple lines, you use three quotes `'''` before and after the comment."
|
|
487 | 468 | {
|
488 | 469 | "cell_type": "code",
|
489 | 470 | "execution_count": null,
|
490 |
| - "metadata": { |
491 |
| - "collapsed": true |
492 |
| - }, |
| 471 | + "metadata": {}, |
493 | 472 | "outputs": [],
|
494 | 473 | "source": [
|
495 | 474 | "# This is how to make a comment on a single line\n",
|
|
535 | 514 | "name": "python",
|
536 | 515 | "nbconvert_exporter": "python",
|
537 | 516 | "pygments_lexer": "ipython3",
|
538 |
| - "version": "3.6.3" |
| 517 | + "version": "3.6.8" |
539 | 518 | }
|
540 | 519 | },
|
541 | 520 | "nbformat": 4,
|
|
0 commit comments