Skip to content

Commit

Permalink
Added a clarifier for boolean and/or combinations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybrown8 committed Nov 20, 2015
1 parent b56486a commit ba2909f
Showing 1 changed file with 64 additions and 5 deletions.
69 changes: 64 additions & 5 deletions lesson4exercises.ipynb
Expand Up @@ -104,6 +104,65 @@
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here's some example code for comparing multiple conditions at a time. You'll use it in the next problem. Here, just focus on understanding what it does. You can use the word \"and\" between two conditions. The whole thing will be true only if both of the sub-parts are true. You can use the word \"or\" between two conditions. The whole thing will be true if either one sub-part or the other is true (as well as if both are true). \n",
"\n",
"AND means that every part must be true for the if statement to be true. OR means that at least one part must be true for the whole thing to be true."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"It's a beautiful sunny day.\n"
]
}
],
"source": [
"weather=\"clear\"\n",
"time=\"daytime\"\n",
"if (weather==\"clear\" and time==\"daytime\"):\n",
" print(\"It's a beautiful sunny day.\")\n",
"elif (weather==\"clear\" and time==\"night\"):\n",
" print(\"It's a good time to watch the stars.\")\n",
"else:\n",
" print(\"I didn't expect that weather.\")\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"First condition\n"
]
}
],
"source": [
"num=12\n",
"if (num > 20 or num < 15):\n",
" print(\"First condition\")\n",
"if (num < 0):\n",
" print(\"Negative number\")\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -192,21 +251,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.3.5"
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit ba2909f

Please sign in to comment.