|
48 | 48 | "cell_type": "markdown",
|
49 | 49 | "metadata": {},
|
50 | 50 | "source": [
|
51 |
| - "Similarly to the [`if`](003_Conditional_Execution.ipynb#Applying-Conditions-with-if,-elif,-and-else) statement, a `for` loop requires that:\n", |
| 51 | + "Similarly to the [`if`](003_Conditional_Execution.ipynb#Applying-Conditions-with-if,-elif,-and-else) statement, a `for` loop has several formatting requirements:\n", |
52 | 52 | "\n",
|
53 |
| - "- There must be a subsequent element in the sequence; the condition following the `for` keyword must be `True`. \n", |
54 |
| - "- You add a `:` at the end of the `for` condition.\n", |
55 |
| - "- You indent all the lines of code that have to be executed in each iteration." |
| 53 | + "- It begins with a `for` condition like `for <variable> in <sequence>` where:\n", |
| 54 | + " - `<sequence>` is the list over which to iterate.\n", |
| 55 | + " - `<variable>` is the name of a variable that will store the current value on each iteration. \n", |
| 56 | + "- A `:` at the end of the `for` condition.\n", |
| 57 | + "- The indentation of all the lines of code that have to be executed in each iteration." |
56 | 58 | ]
|
57 | 59 | },
|
58 | 60 | {
|
|
414 | 416 | "The <button class='btn btn-default btn-xs'><i class=\"fa fa-stop\"></i></button> button in the Toolbar stops the execution of a **Code** cell. "
|
415 | 417 | ]
|
416 | 418 | },
|
| 419 | + { |
| 420 | + "cell_type": "markdown", |
| 421 | + "metadata": {}, |
| 422 | + "source": [ |
| 423 | + " " |
| 424 | + ] |
| 425 | + }, |
| 426 | + { |
| 427 | + "cell_type": "markdown", |
| 428 | + "metadata": { |
| 429 | + "solution2": "hidden", |
| 430 | + "solution2_first": true |
| 431 | + }, |
| 432 | + "source": [ |
| 433 | + "<img align=\"left\" width=\"6%\" style=\"padding-right:10px;\" src=\"images/test.png\">\n", |
| 434 | + "\n", |
| 435 | + "Add the code required to pop and then print all the values from the `sal_list`:" |
| 436 | + ] |
| 437 | + }, |
| 438 | + { |
| 439 | + "cell_type": "code", |
| 440 | + "execution_count": null, |
| 441 | + "metadata": { |
| 442 | + "solution2": "hidden" |
| 443 | + }, |
| 444 | + "outputs": [], |
| 445 | + "source": [ |
| 446 | + "sal_list = [32.1, 33.7, 35.0, 32.5, 31.9] # water salinity in PSU\n", |
| 447 | + "\n", |
| 448 | + "while len(sal_list) > 0:\n", |
| 449 | + " \n", |
| 450 | + " removed_value = sal_list.pop()\n", |
| 451 | + " print(\"Removed element: \" + str(removed_value))" |
| 452 | + ] |
| 453 | + }, |
| 454 | + { |
| 455 | + "cell_type": "code", |
| 456 | + "execution_count": null, |
| 457 | + "metadata": {}, |
| 458 | + "outputs": [], |
| 459 | + "source": [ |
| 460 | + "sal_list = [32.1, 33.7, 35.0, 32.5, 31.9] # water salinity in PSU" |
| 461 | + ] |
| 462 | + }, |
417 | 463 | {
|
418 | 464 | "cell_type": "markdown",
|
419 | 465 | "metadata": {},
|
|
0 commit comments