Skip to content

Instantly share code, notes, and snippets.

@prafullkotecha
Created January 13, 2019 16:22
Show Gist options
  • Save prafullkotecha/221ca6853758594aa6547eec5dbcfead to your computer and use it in GitHub Desktop.
Save prafullkotecha/221ca6853758594aa6547eec5dbcfead to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a href=\"http://cocl.us/topNotebooksPython101Coursera\"><img src = \"https://ibm.box.com/shared/static/yfe6h4az47ktg2mm9h05wby2n7e8kei3.png\" width = 750, align = \"center\"></a>\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://www.bigdatauniversity.com\"><img src = \"https://ibm.box.com/shared/static/ugcqz6ohbvff804xp84y4kqnvvk3bq1g.png\" width = 300, align = \"center\"></a>\n",
"\n",
"<h1 align=center><font size = 5>LOOPS AND CONDITIONAL EXECUTION IN PYTHON</font></h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Table of Contents\n",
"\n",
"\n",
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
"<li><a href=\"#ref1\">Comparison Operators </a></li>\n",
"<li><a href=\"#ref2\">Branching</a></li>\n",
"<li><a href=\"#ref3\">Logic Operation </a></li>\n",
"<br>\n",
"<p></p>\n",
"Estimated Time Needed: <strong>15 min</strong>\n",
"</div>\n",
"\n",
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a id=\"ref1\"></a>\n",
"<center><h2>COMPARISON OPERATORS</h2></center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Comparison operations compare some value or operand and, based on a condition, they produce a Boolean. When comparing two values you can use these operators:\n",
"\n",
"<ul>\n",
"<li>equal: `==`\n",
"<li>not equal: `!=`\n",
"<li>greater than: `>`</li>\n",
"<li>less than: `<`</li>\n",
"<li>greater than or equal to: `>=`</li>\n",
"<li>less than or equal to: `<=`</li>\n",
"</ul>\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's say we assign **a** a value of 6. We can use the equality operator denoted with two equal (**==**) signs to determine if two values are equal."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a=5\n",
"\n",
"a==6"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The result is false, as 5 does not equal 6."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the following equality comparison operator **i>5**. If the value of the left operand, in this case the variable **i**, is higher than the value of the right operand, in this case 5, then the condition becomes **True** or else we get a **False**. If we set **i** equal to 6, we see that 6 is larger than 5 and as a result, we get **True**. \n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"i=6\n",
"i>5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we set **i=2** the condition is false as 2 is less than 5:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"i=2\n",
"i>5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Let's display some values for **i** in the figure. Set the values greater than 5 in green and the rest in red. The green region represents where the condition is **True**, the red where the statement is false. If the value of **i** is 2, we get **False** as the 2 falls in the red region. Similarly, if the value for **i** is 6 we get a **True** as the condition falls in the green region. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a ><img src = \"https://ibm.box.com/shared/static/xr028o5qcvxgdn3i1rqsjbxwaq5gb4ki.gif\" width = 500, align = \"center\"></a>\n",
" <h4 align=center> \n",
" </h4>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The inequality test uses an exclamation mark preceding the equal sign, if two operands are not equal then the condition becomes **True**. For example, the following condition will produce **True** as long as the value of **i** is not equal to 6:\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"i=2\n",
"i!=6"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When **i** equals six the expression produces **False**. "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"i=6\n",
"i!=6"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can use a number line as before, when the condition is **True** the corresponding numbers are marked in green and for where the condition is **False** the corresponding number is marked in red. If we set **i** equal to 2 the operator is true as 2 is in the green region. If we set **i** equal to 6 we get a **False** as the condition falls in the red region."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a ><img src = https://ibm.box.com/shared/static/pf6rvks8eh4e1riwki59gx7s9rvmidu4.gif width = 500, align = \"center\"></a>\n",
" <h4 align=center> \n",
" </h4>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can use the same methods on strings, for example, if we use an equality operator on two different strings. As the strings are not equal, we get a **False**."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"ACDC\"==\"Michael Jackson\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" If we use the inequality operator, we get a **True** as the strings are not equal."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"ACDC\"!=\"Michael Jackson\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can also perform inequality operations, the order of the letter depends on the ASCII value. The decimal value shown in the following table represents the order of the character:\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a ><img src =https://ibm.box.com/shared/static/4grvg0o9bvhp80u88lkfcsdlvg4whvzs.svg width = 1000, align = \"center\"></a>\n",
" <h4 align=center> \n",
" </h4>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For example, the decimal equivalent of **!** is 21, while the decimal equivalent of **+** is 43. Therefore **+** is larger than **!**."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'+'>'!'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Similarly, the value for **A** is 101, and the value for **B** is 102 therefore:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'B'>'A'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" When there are multiple letters, the first letter takes precedence in ordering:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'BA'>'AB'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a id=\"ref2\"></a>\n",
"<center><h2>Branching</h2></center>\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Branching allows us to run different statements for different inputs. It is helpful to think of an **if statement** as a locked room, if the statement is true you can enter the room and your program will run some predefined task, but if the statement is false your program will skip the task.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" For example, consider the blue rectangle representing an ACDC concert. If the individual is 18 or older, they can enter the ACDC concert. If they are under the age of 18 they cannot enter the concert. We have the if statement and we have the expression that can be **True** or **False**, the brackets are not necessary. We have a colon within an indent; then we have the expression that is run if the condition is **True**. The statements after the **if statement** will run regardless of whether the condition is true or false."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"move on\n"
]
}
],
"source": [
"age=19\n",
"age=18\n",
"\n",
"#expression that can be true or false\n",
"if age>18:\n",
" \n",
" #within an indent, we have the expression that is run if the condition is true\n",
" print(\"you can enter\" )\n",
"\n",
"\n",
"#The statements after the if statement will run regardless if the condition is true or false \n",
"print(\"move on\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Try uncommenting the age variable**.\n",
"\n",
"It is helpful to use the following diagram to illustrate the process. On the left side, we see what happens when the condition is **True**. The person enters the ACDC concert representing the code in the indent being executed; they then move on. On the right side, we see what happens when the condition is **False**; the person is not granted access, and the person moves on. In this case, the segment of code in the indent does not run, but the rest of the statements are run. \n",
" \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a ><img src =https://ibm.box.com/shared/static/l7y2t7evi5gy5n5qry718gyejkha2azk.gif width = 1000, align = \"center\"></a>\n",
" <h4 align=center> \n",
" </h4>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The **else** statement will run a different block of code if the same condition is false. Let's use the ACDC concert analogy again. If the user is 17 they can not go to the ACDC concert, but they can go to the Meatloaf concert.\n",
"The syntax of the **else** statement is similar; we simply append the statement **else** with the new condition.\n",
"Try changing the values of **age** to see what happens: "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"you can enter\n",
"move on\n"
]
}
],
"source": [
"age=18\n",
"age=19\n",
"if age>18:\n",
" \n",
" print(\"you can enter\" )\n",
" \n",
"else:\n",
" print(\"go see Meat Loaf\" )\n",
" \n",
"\n",
"print(\"move on\")\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The process is demonstrated below, where each of the possibilities is illustrated on each side of the image. On the left is the case where the age is 17, we set the value of the variable age to 17, and this corresponds to the individual attending the Meatloaf concert. The right portion shows what happens when the individual is over 18, and the individual is granted access to the concert."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a ><img src =https://ibm.box.com/shared/static/hkf892cpt2tx7vrt072jdp4khne0mv00.gif width = 1000, align = \"center\"></a>\n",
" <h4 align=center> \n",
" </h4>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The **elif** statement, short for else if, allows us to check additional conditions if the proceeding condition is false. If the condition is **True**, the alternate expressions will be run. Consider the concert example, where if the individual is 18 they will go to the Pink Floyd concert instead of attending the ACDC or Meat-loaf concert. The person of 18 years of age enters the area, and as they are not over 19 years of age they can not see ACDC, but as they are 18 years of age, they attend Pink Floyd. After seeing Pink Floyd, they move on. The syntax of the **elif** statement is similar in that we merely add the statement **elif** with the condition. We then add the expression we would like to execute it the statement is **True** with an indent."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"go see Pink Floyd\n",
"move on\n"
]
}
],
"source": [
"age=18\n",
"if age>18:\n",
" \n",
" print(\"you can enter\" )\n",
"elif age==18:\n",
" print(\"go see Pink Floyd\")\n",
"else:\n",
" print(\"go see Meat Loaf\" )\n",
" \n",
"\n",
"print(\"move on\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The three combinations are shown in the figure below. The left-most region shows what happens when the individual is less than 18 years of age. The central component shows when the individual is 18. The rightmost shows when the individual is over 18."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a ><img src =https://ibm.box.com/shared/static/bfdcim06oly4u5t3x9dthskr0chxwyys.gif width = 1000, align = \"center\"></a>\n",
" <h4 align=center> \n",
" </h4>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Look at the following code:\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album year is greater than 1980\n",
"\n",
"do something..\n"
]
}
],
"source": [
"album_year = 1983\n",
"# album_year=1970\n",
"if album_year > 1980:\n",
" print(\"Album year is greater than 1980\")\n",
" \n",
"print(\"\")\n",
"print('do something..')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Feel free to change **`album_year`** value to other values -- you'll see that the result changes!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice that the code in the above **indented** block will only be executed if the results are **True**. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Write an if statement to determine if an album had a rating greater than 8. Test it using the rating for the album “Back in Black” that had a rating of 8.5. If the statement is true print \"this album is Amazing !\"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This album is Amazing!\n"
]
}
],
"source": [
"back_in_black_rating = 8.5\n",
"amazing_album_rating = 8\n",
"if (back_in_black_rating > amazing_album_rating):\n",
" print(\"This album is Amazing!\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <div align=\"right\">\n",
"<a href=\"#q1\" class=\"btn btn-default\" data-toggle=\"collapse\">Click here for the solution</a>\n",
"\n",
"</div>\n",
"<div id=\"q1\" class=\"collapse\">\n",
"```\n",
"rating=8.5\n",
"\n",
"if rating>8:\n",
" print \"this album is Amazing !\"\n",
"\n",
"```\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-success alertsuccess\" style=\"margin-top: 20px\">\n",
"**Tip**: This syntax can be spread over multiple lines for ease of creation and legibility.\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As before, we can add an **else** block to the **if** block. The code in the **else** block will only be executed if the result is **False**.\n",
"\n",
"\n",
"**Syntax:** \n",
"\n",
"if (condition):\n",
" # do something\n",
"else:\n",
" # do something else"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" If the condition in the if statement is false, the statement after the else block will execute. This is demonstrated in the figure: \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a ><img src = \"https://ibm.box.com/shared/static/zygha3mwjwrcfok2jrivu7z5iirt4xgt.png\" width = 500, align = \"center\"></a>\n",
" <h4 align=center> \n",
" </h4>\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"album_year = 1983\n",
"#album_year=1970\n",
"if album_year > 1980:\n",
" print(\"Album year is greater than 1980\")\n",
"else:\n",
" print(\"less than 1980\")\n",
"print(\"\")\n",
"print('do something..')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Feel free to change the **`album_year`** value to other values -- you'll see that the result changes based on it!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Write an if-else statement that performs the following. If the rating is larger then eight print “this album is amazing”. If the rating is less, then or equal to 8 print “this album is ok”. \n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This album is OK.\n"
]
}
],
"source": [
"thriller_rating = 8\n",
"amazing_album_rating = 8\n",
"if (thriller_rating > amazing_album_rating):\n",
" print(\"This album is Amazing!\")\n",
"else:\n",
" print(\"This album is OK.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <div align=\"right\">\n",
"<a href=\"#q2\" class=\"btn btn-default\" data-toggle=\"collapse\">Click here for the solution</a>\n",
"\n",
"</div>\n",
"<div id=\"q2\" class=\"collapse\">\n",
"```\n",
"rating = 8.5\n",
"#try with this value\n",
"#rating = 8\n",
"if rating > 8:\n",
" print \"this album is amazing\"\n",
"else:\n",
" print \"this album is ok\n",
"```\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a id=\"ref3\"></a>\n",
"<center><h2>Logical operators</h2></center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Sometimes you want to check more than one condition at once. For example, you might want to check if one condition and another condition is **True**. Logical operators allow you to combine or modify conditions.\n",
"<ul>\n",
"<li> `and`\n",
"<li> `or`\n",
"<li> `not` \n",
"</ul>\n",
"\n",
"These operators are summarized for two variables using the following truth tables: "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a ><img src = \"https://ibm.box.com/shared/static/kbkqfu6apx9wczu79j6ug8xs9c6tt3d3.png\" width = 500, align = \"center\"></a>\n",
" <h4 align=center> \n",
" </h4>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The **and** statement is only **True** when both conditions are true. The **or** statement is true if one condition is **True**. Finally the **not** statement outputs the opposite truth value."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We would like to determine if an album was released after 1980 and before 1990. Both time periods between 1981 and 1989 satisfy this condition. This is demonstrated in the figure below. The green on lines **a** and **b** represents periods where the statement is **True**. The green on line **c** represents where both conditions are **True**, this corresponds to where the green regions overlap. \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a ><img src = \"https://ibm.box.com/shared/static/mtvdx315p1a2bp6e1vqv3uppnzp3wu2i.png\" width = 500, align = \"center\"></a>\n",
" <h4 align=center> An example of an if else statement \n",
" </h4>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The block of code to perform this check is given by:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album year was in between 1981 and 1989\n",
"\n",
"Do Stuff..\n"
]
}
],
"source": [
"album_year = 1980\n",
"\n",
"if(album_year > 1979) and (album_year < 1990):\n",
" print (\"Album year was in between 1981 and 1989\")\n",
" \n",
"print(\"\")\n",
"print(\"Do Stuff..\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To determine if an album was released before 1980 or after 1990, we can use an **or** statement. Periods before 1981 or after 1989 satisfy this condition. This is demonstrated in the following figure, the color green in **a** and **b** represents periods where the statement is true. The color green in **c** represents where at least one of the conditions \n",
"are true. \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <a ><img src = \"https://ibm.box.com/shared/static/lw0zehvs2rrs9yjit5i0mf2zgtfe6rl1.png\" width = 500, align = \"center\"></a>\n",
" <h4 align=center> An example of an if else statement \n",
" </h4>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The block of code to perform this check is given by:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album was not made in the 1980's\n"
]
}
],
"source": [
"album_year = 1990\n",
"\n",
"if(album_year < 1980) or (album_year > 1989):\n",
" print (\"Album was not made in the 1980's\")\n",
"else:\n",
" print(\"The Album was made in the 1980's \")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The **not** statement checks if the statement is false:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album year is not 1984\n"
]
}
],
"source": [
"album_year = 1983\n",
"\n",
"if not (album_year == '1984'):\n",
" print (\"Album year is not 1984\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Write an if statement to determine if an album came out before 1980 or in the years: 1991 or 1993. If the condition is true print out the year the album came out.\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album came out in 1969\n"
]
}
],
"source": [
"album_year = 1969\n",
"if (album_year < 1980 or album_year == 1991 or album_year == 1993):\n",
" print(\"Album came out in \", album_year)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# <div align=\"right\">\n",
"<a href=\"#q3\" class=\"btn btn-default\" data-toggle=\"collapse\">Click here for the solution</a>\n",
"\n",
"</div>\n",
"<div id=\"q3\" class=\"collapse\">\n",
"```\n",
"album_year = 1993\n",
"if (album_year<1980) or (album_year==1991) or (album_year==1993):\n",
" print \"the year is\",album_year \n",
"\n",
"```\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-success alertsuccess\" style=\"margin-top: 20px\">\n",
"**Tip**: All the expressions will return the value in Boolean format -- this format can only house two values: true or false!\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
" <a href=\"http://cocl.us/bottemNotebooksPython101Coursera\"><img src = \"https://ibm.box.com/shared/static/irypdxea2q4th88zu1o1tsd06dya10go.png\" width = 750, align = \"center\"></a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"# About the Authors: \n",
"\n",
" [Joseph Santarcangelo]( https://www.linkedin.com/in/joseph-s-50398b136/) has a PhD in Electrical Engineering, his research focused on using machine learning, signal processing, and computer vision to determine how videos impact human cognition. Joseph has been working for IBM since he completed his PhD."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" <hr>\n",
"Copyright &copy; 2017 [cognitiveclass.ai](cognitiveclass.ai?utm_source=bducopyrightlink&utm_medium=dswb&utm_campaign=bdu). This notebook and its source code are released under the terms of the [MIT License](https://bigdatauniversity.com/mit-license/).​"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
},
"widgets": {
"state": {},
"version": "1.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment