|
5 | 5 | "cell_type": "markdown", |
6 | 6 | "source": [ |
7 | 7 | "# Loops, Logic, and Data Structures\n", |
8 | | - "\n", |
9 | | - "- practical project: Fibonacci sequence\n", |
10 | | - "- for loops,\n", |
11 | | - "- while loops,\n", |
12 | | - "- if statements," |
| 8 | + "\n" |
13 | 9 | ], |
14 | 10 | "id": "9c7ff0bbc2c8e91d" |
15 | 11 | }, |
16 | 12 | { |
17 | 13 | "metadata": {}, |
18 | 14 | "cell_type": "markdown", |
19 | 15 | "source": [ |
20 | | - "Today we'll be learning about loops and logical functions in Python. These are very handy when you want to iterate through data and perform actions based on a condition.\n", |
| 16 | + "Today we'll be learning about loops and logical functions in Python. Loops allow you to perform a specific action multipe time in a row, which can be very handy when you want to iterate through data and perform actions based on a condition. Logical functions allow you to perform an action _if_ a condition is true or not.\n", |
21 | 17 | "\n", |
22 | 18 | "## Conditional Operators in Python\n", |
23 | | - "The basics of conditional operators are `if`, `elif`, and `else`. These form the backbone of logic in Python. It's like writing a sentence, \"If Joe likes apples, give him an apple, if he likes something else like oranges, give him an orange. If all else fails, give him a banana.\"\n", |
| 19 | + "The basics of conditional operators are `if`, `elif`, and `else`. These form the backbone of logic in Python. It's like writing a sentence, \"If Alex Yin likes apples, give him an apple, if he likes something else like oranges, give him an orange. If all else fails, give him a monster.\"\n", |
24 | 20 | "\n", |
25 | 21 | "`if` tells the computer to execute the following code block _if_ a condition is true.<br>\n", |
26 | 22 | "`elif` tells the computer to execute the following code block _if_ nothing _el_se above was true. (optional, but requires an if)<br>\n", |
|
71 | 67 | "cell_type": "code", |
72 | 68 | "source": [ |
73 | 69 | "bananas = 8\n", |
74 | | - "eggplants = 2" |
| 70 | + "eggplants = 2\n", |
| 71 | + "# write your code here" |
75 | 72 | ], |
76 | 73 | "id": "96b54220aa653219", |
77 | 74 | "outputs": [], |
78 | 75 | "execution_count": null |
79 | 76 | }, |
| 77 | + { |
| 78 | + "metadata": {}, |
| 79 | + "cell_type": "markdown", |
| 80 | + "source": "Try fixing this horrendeously wrong if statement!", |
| 81 | + "id": "8034b641777d2cbf" |
| 82 | + }, |
| 83 | + { |
| 84 | + "metadata": {}, |
| 85 | + "cell_type": "code", |
| 86 | + "outputs": [], |
| 87 | + "execution_count": null, |
| 88 | + "source": [ |
| 89 | + "i like cheese = true\n", |
| 90 | + "if i like cheese\n", |
| 91 | + " print(i like cheese!)\n", |
| 92 | + "else\n", |
| 93 | + " print get out of wisconsin!" |
| 94 | + ], |
| 95 | + "id": "6513091686b4e2e0" |
| 96 | + }, |
80 | 97 | { |
81 | 98 | "metadata": {}, |
82 | 99 | "cell_type": "markdown", |
|
383 | 400 | "metadata": {}, |
384 | 401 | "cell_type": "markdown", |
385 | 402 | "source": [ |
386 | | - "# Timing your loops:\n", |
| 403 | + "## optional! Timing your loops:\n", |
387 | 404 | "\n", |
388 | 405 | "if you want your loops to execute at a specific interval, perhaps to give the illusion of someone typing out on screen, or to perform an action every 10 seconds, you can add a delay at the end of each loop using the `time` library. We're importing the time library, which comes pre-installed. We'll talk more about imports in a later chapter, but we're basically using code that other people have already written to help us in our program." |
389 | 406 | ], |
|
0 commit comments