Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Day_2/07_Lists.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
"source": [
"* This makes lists different from strings. \n",
"* You cannot change the characters in a [string](https://github.com/dlab-berkeley/python-intensive/blob/master/Glossary.md#string) after it has been created.\n",
" * *Immutable*: cannot be changed after creation.\n",
" * In contrast, lists are *mutable*: they can be modified in place."
" * [*Immutable*](https://github.com/dlab-berkeley/python-fundamentals/blob/master/Glossary.md#immutable): cannot be changed after creation.\n",
" * In contrast, lists are [*mutable*](https://github.com/dlab-berkeley/python-fundamentals/blob/master/Glossary.md#mutable): they can be modified in place."
]
},
{
Expand Down Expand Up @@ -677,7 +677,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.7.1"
}
},
"nbformat": 4,
Expand Down
24 changes: 4 additions & 20 deletions Day_2/08_Loops.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"source": [
"* Read `total = total + number` as:\n",
" * Add the current value of the [loop variable](https://github.com/dlab-berkeley/python-intensive/blob/master/Glossary.md#loop-variable) `number` to the current value of the accumulator variable `total`.\n",
" * Assign this new value to to `total`, replacing the current value.\n",
" * Assign this new value to `total`, replacing the current value.\n",
" \n",
"Instead of writing `total = total + number`, this can be simplified to `total += number`. This will reassign total to the current value of total plus the current value of number:"
]
Expand Down Expand Up @@ -340,7 +340,7 @@
"\n",
"Below is a list of presidents. Create a new list that contains only the last name of each president.\n",
"\n",
"(HINT: Look at string methods!)"
"(HINT: Use a `for` loop Look at string methods!)"
]
},
{
Expand Down Expand Up @@ -369,29 +369,13 @@
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now sort the list alphabetically by last name (HINT: look up `sorted`):"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 4: Range\n",
"\n",
"Using `range` and a for loop, calculate the factorial of 42 (the product of all integers up to and including 42)."
"Using `range` and a `for` loop to calculate the factorial of 42 (which is the product of all integers up to and including 42)."
]
},
{
Expand Down Expand Up @@ -445,7 +429,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.7.1"
}
},
"nbformat": 4,
Expand Down
88 changes: 51 additions & 37 deletions Day_2/09_Conditionals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@
"* * * * *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## `bool` data type\n",
"\n",
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"type(True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"5 > 6"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -37,7 +64,7 @@
"* An `if` statement (more properly called a *conditional* statement)\n",
" controls whether some block of code is executed or not.\n",
"* Structure is similar to a `for` statement:\n",
" * First line opens with `if` and ends with a colon\n",
" * First line opens with `if`, contains a *Boolean* variable or expression, and ends with a colon\n",
" * Body containing one or more statements is indented (usually by 4 spaces)\n"
]
},
Expand Down Expand Up @@ -278,9 +305,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"presidents_full = [\"George Washington\", \"John Adams\", \"Thomas Jefferson\", \"James Madison\", \"James Monroe\", \\\n",
Expand All @@ -297,9 +322,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
},
Expand All @@ -322,9 +345,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"song = '''Row, row, row your boat\n",
Expand All @@ -342,17 +363,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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)"
"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",
"\n",
"(HINT: first remove punctuation using `punctation` below)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
"source": [
"from string import punctuation"
]
},
{
"cell_type": "markdown",
Expand All @@ -365,17 +388,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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",
"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",
"\n",
"(HINT: remember what % does, lookup \"enumerate\")\n",
"\n",
"Source: http://titus.uni-frankfurt.de/texte/etcs/germ/ahd/otfrid/otfri.htm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"text = '''si sálida gimúati sálomones gúati, \n",
Expand Down Expand Up @@ -431,32 +454,25 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# HINT: remember what % does, lookup enumerate"
]
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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?"
"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",
"\n",
"(HINT: first remove punctuation and lookup \"enumerate\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# HINT: first remove punctuation, tab is represented by \\t, lookup enumerate\n",
"from string import punctuation"
]
"source": []
},
{
"cell_type": "markdown",
Expand All @@ -479,9 +495,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
}
Expand All @@ -502,7 +516,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.7.1"
}
},
"nbformat": 4,
Expand Down
Loading