Skip to content

Instantly share code, notes, and snippets.

@mde-2590
Created April 8, 2019 22:36
Show Gist options
  • Save mde-2590/191af19bf54ff927281158a98396f492 to your computer and use it in GitHub Desktop.
Save mde-2590/191af19bf54ff927281158a98396f492 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": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Condition Equal\n",
"\n",
"a = 5\n",
"a == 6"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Greater than Sign\n",
"\n",
"i = 6\n",
"i > 5"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Greater than Sign\n",
"\n",
"i = 2\n",
"i > 5"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Inequality Sign\n",
"\n",
"i = 2\n",
"i != 6"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Inequality Sign\n",
"\n",
"i = 6\n",
"i != 6"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Use Equality sign to compare the strings\n",
"\n",
"\"ACDC\" == \"Michael Jackson\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Use Inequality sign to compare the strings\n",
"\n",
"\"ACDC\" != \"Michael Jackson\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Compare characters\n",
"\n",
"'B' > 'A'"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Compare characters\n",
"\n",
"'BA' > 'AB'"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"you can enter\n",
"move on\n"
]
}
],
"source": [
"# If statement example\n",
"\n",
"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",
"#The statements after the if statement will run regardless if the condition is true or false \n",
"print(\"move on\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"move on\n"
]
}
],
"source": [
"# If statement example\n",
"\n",
"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",
"#The statements after the if statement will run regardless if the condition is true or false \n",
"print(\"move on\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"move on\n"
]
}
],
"source": [
"# If statement example\n",
"\n",
"#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",
"#The statements after the if statement will run regardless if the condition is true or false \n",
"print(\"move on\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"go see Meat Loaf\n",
"move on\n"
]
}
],
"source": [
"# Else statement example\n",
"\n",
"age = 18\n",
"# age = 19\n",
"\n",
"if age > 18:\n",
" print(\"you can enter\" )\n",
"else:\n",
" print(\"go see Meat Loaf\" )\n",
" \n",
"print(\"move on\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"go see Pink Floyd\n",
"move on\n"
]
}
],
"source": [
"# Elif statment example\n",
"\n",
"age = 18\n",
"\n",
"if age > 18:\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",
"print(\"move on\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"do something..\n"
]
}
],
"source": [
"# Condition statement example\n",
"\n",
"album_year = 1983\n",
"album_year = 1970\n",
"\n",
"if album_year > 1980:\n",
" print(\"Album year is greater than 1980\")\n",
" \n",
"print('do something..')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album year is greater than 1980\n",
"do something..\n"
]
}
],
"source": [
"# Condition statement example\n",
"\n",
"album_year = 1983\n",
"#album_year = 1970\n",
"\n",
"if album_year > 1980:\n",
" print(\"Album year is greater than 1980\")\n",
"else:\n",
" print(\"less than 1980\")\n",
"\n",
"print('do something..')"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"less than 1980\n",
"do something..\n"
]
}
],
"source": [
"# Condition statement example\n",
"\n",
"#album_year = 1983\n",
"album_year = 1970\n",
"\n",
"if album_year > 1980:\n",
" print(\"Album year is greater than 1980\")\n",
"else:\n",
" print(\"less than 1980\")\n",
"\n",
"print('do something..')"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album year was in between 1980 and 1989\n",
"\n",
"Do Stuff..\n"
]
}
],
"source": [
"# Condition statement example\n",
"\n",
"album_year = 1980\n",
"\n",
"if(album_year > 1979) and (album_year < 1990):\n",
" print (\"Album year was in between 1980 and 1989\")\n",
" \n",
"print(\"\")\n",
"print(\"Do Stuff..\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album was not made in the 1980's\n"
]
}
],
"source": [
"# Condition statement example\n",
"\n",
"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": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Album year is not 1984\n"
]
}
],
"source": [
"# Condition statement example\n",
"\n",
"album_year = 1983\n",
"\n",
"if not (album_year == '1984'):\n",
" print (\"Album year is not 1984\")\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This album is Amazing!\n"
]
}
],
"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",
"\n",
"rating = 8.5\n",
"if rating > 8:\n",
" print (\"This album is Amazing!\")\n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This album is Amazing!\n"
]
}
],
"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 than or equal to 8 print “this album is ok”.\n",
"\n",
"rating = 8.5\n",
"if rating > 8:\n",
" print (\"This album is Amazing!\")\n",
"else:\n",
" print (\"This album is ok\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"this album came out already\n"
]
}
],
"source": [
"\n",
"#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",
"album_year = 1979\n",
"\n",
"if album_year < 1980 or album_year == 1991 or album_year == 1993:\n",
" print (\"this album came out already\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment