|
28 | 28 | "* * * * *" |
29 | 29 | ] |
30 | 30 | }, |
| 31 | + { |
| 32 | + "cell_type": "markdown", |
| 33 | + "metadata": {}, |
| 34 | + "source": [ |
| 35 | + "## `bool` data type\n", |
| 36 | + "\n", |
| 37 | + "A *Boolean* variable is one that can take the values of either `True` or `False`. They are used to indicate the presence or absence of a certain condition. You can test the value of a variable and a *Boolean* value will be returned. In Python, `bool` is the data type for *Boolean* values." |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "code", |
| 42 | + "execution_count": null, |
| 43 | + "metadata": {}, |
| 44 | + "outputs": [], |
| 45 | + "source": [ |
| 46 | + "type(True)" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": null, |
| 52 | + "metadata": {}, |
| 53 | + "outputs": [], |
| 54 | + "source": [ |
| 55 | + "5 > 6" |
| 56 | + ] |
| 57 | + }, |
31 | 58 | { |
32 | 59 | "cell_type": "markdown", |
33 | 60 | "metadata": {}, |
|
37 | 64 | "* An `if` statement (more properly called a *conditional* statement)\n", |
38 | 65 | " controls whether some block of code is executed or not.\n", |
39 | 66 | "* Structure is similar to a `for` statement:\n", |
40 | | - " * First line opens with `if` and ends with a colon\n", |
| 67 | + " * First line opens with `if`, contains a *Boolean* variable or expression, and ends with a colon\n", |
41 | 68 | " * Body containing one or more statements is indented (usually by 4 spaces)\n" |
42 | 69 | ] |
43 | 70 | }, |
|
278 | 305 | { |
279 | 306 | "cell_type": "code", |
280 | 307 | "execution_count": null, |
281 | | - "metadata": { |
282 | | - "collapsed": true |
283 | | - }, |
| 308 | + "metadata": {}, |
284 | 309 | "outputs": [], |
285 | 310 | "source": [ |
286 | 311 | "presidents_full = [\"George Washington\", \"John Adams\", \"Thomas Jefferson\", \"James Madison\", \"James Monroe\", \\\n", |
|
297 | 322 | { |
298 | 323 | "cell_type": "code", |
299 | 324 | "execution_count": null, |
300 | | - "metadata": { |
301 | | - "collapsed": true |
302 | | - }, |
| 325 | + "metadata": {}, |
303 | 326 | "outputs": [], |
304 | 327 | "source": [] |
305 | 328 | }, |
|
322 | 345 | { |
323 | 346 | "cell_type": "code", |
324 | 347 | "execution_count": null, |
325 | | - "metadata": { |
326 | | - "collapsed": true |
327 | | - }, |
| 348 | + "metadata": {}, |
328 | 349 | "outputs": [], |
329 | 350 | "source": [ |
330 | 351 | "song = '''Row, row, row your boat\n", |
|
342 | 363 | "cell_type": "markdown", |
343 | 364 | "metadata": {}, |
344 | 365 | "source": [ |
345 | | - "Using string methods, for loops, and conditionals, write some code to `print` only the rhyming words (HINT: we'll be simplistic and assume it rhymes if the last 3 characters are the same)" |
| 366 | + "Using string methods, for loops, and conditionals, write some code to `print` only the rhyming words. We'll be simplistic and assume it rhymes if the last 3 characters are the same.\n", |
| 367 | + "\n", |
| 368 | + "(HINT: first remove punctuation using `punctation` below)" |
346 | 369 | ] |
347 | 370 | }, |
348 | 371 | { |
349 | 372 | "cell_type": "code", |
350 | 373 | "execution_count": null, |
351 | | - "metadata": { |
352 | | - "collapsed": true |
353 | | - }, |
| 374 | + "metadata": {}, |
354 | 375 | "outputs": [], |
355 | | - "source": [] |
| 376 | + "source": [ |
| 377 | + "from string import punctuation" |
| 378 | + ] |
356 | 379 | }, |
357 | 380 | { |
358 | 381 | "cell_type": "markdown", |
|
365 | 388 | "cell_type": "markdown", |
366 | 389 | "metadata": {}, |
367 | 390 | "source": [ |
368 | | - "In poetry, an acrostic is a message created by taking certain letters in a pattern over lines. One 9th century German writer, Otfrid of Weissenburg, was notorius for his early use of acrostics, one instance of which is in the text below: *Salomoni episcopo Otfridus*. His message can be found by taking the first character of every other line. Print Otfrid's message! \n", |
| 391 | + "In poetry, an acrostic is a message created by taking certain letters in a pattern over lines. One 9th century German writer, Otfrid of Weissenburg, was notorius for his early use of acrostics, one of which is in the text below: *Salomoni episcopo Otfridus*. His message can be found by taking the first character of every other line. Print Otfrid's message! \n", |
| 392 | + "\n", |
| 393 | + "(HINT: remember what % does, lookup \"enumerate\")\n", |
369 | 394 | "\n", |
370 | 395 | "Source: http://titus.uni-frankfurt.de/texte/etcs/germ/ahd/otfrid/otfri.htm" |
371 | 396 | ] |
372 | 397 | }, |
373 | 398 | { |
374 | 399 | "cell_type": "code", |
375 | 400 | "execution_count": null, |
376 | | - "metadata": { |
377 | | - "collapsed": true |
378 | | - }, |
| 401 | + "metadata": {}, |
379 | 402 | "outputs": [], |
380 | 403 | "source": [ |
381 | 404 | "text = '''si sálida gimúati sálomones gúati, \n", |
|
431 | 454 | { |
432 | 455 | "cell_type": "code", |
433 | 456 | "execution_count": null, |
434 | | - "metadata": { |
435 | | - "collapsed": true |
436 | | - }, |
| 457 | + "metadata": {}, |
437 | 458 | "outputs": [], |
438 | | - "source": [ |
439 | | - "# HINT: remember what % does, lookup enumerate" |
440 | | - ] |
| 459 | + "source": [] |
441 | 460 | }, |
442 | 461 | { |
443 | 462 | "cell_type": "markdown", |
444 | 463 | "metadata": {}, |
445 | 464 | "source": [ |
446 | | - "Otfrid was more skillful than to settle for the first letter of every other line. What happens if you extract the last letter of the last word of each line, for every other line starting on the second line?" |
| 465 | + "Otfrid was more skillful than to settle for the first letter of every other line. What happens if you extract the last letter of the last word of each line, for every other line starting on the second line?\n", |
| 466 | + "\n", |
| 467 | + "(HINT: first remove punctuation and lookup \"enumerate\")" |
447 | 468 | ] |
448 | 469 | }, |
449 | 470 | { |
450 | 471 | "cell_type": "code", |
451 | 472 | "execution_count": null, |
452 | | - "metadata": { |
453 | | - "collapsed": true |
454 | | - }, |
| 473 | + "metadata": {}, |
455 | 474 | "outputs": [], |
456 | | - "source": [ |
457 | | - "# HINT: first remove punctuation, tab is represented by \\t, lookup enumerate\n", |
458 | | - "from string import punctuation" |
459 | | - ] |
| 475 | + "source": [] |
460 | 476 | }, |
461 | 477 | { |
462 | 478 | "cell_type": "markdown", |
|
479 | 495 | { |
480 | 496 | "cell_type": "code", |
481 | 497 | "execution_count": null, |
482 | | - "metadata": { |
483 | | - "collapsed": true |
484 | | - }, |
| 498 | + "metadata": {}, |
485 | 499 | "outputs": [], |
486 | 500 | "source": [] |
487 | 501 | } |
|
502 | 516 | "name": "python", |
503 | 517 | "nbconvert_exporter": "python", |
504 | 518 | "pygments_lexer": "ipython3", |
505 | | - "version": "3.6.1" |
| 519 | + "version": "3.7.1" |
506 | 520 | } |
507 | 521 | }, |
508 | 522 | "nbformat": 4, |
|
0 commit comments