From dc9e3775657fad70613b367c23fcd19a6228c7cc Mon Sep 17 00:00:00 2001 From: Leonardo Santos Date: Sat, 24 Mar 2018 00:49:53 -0300 Subject: [PATCH 1/6] My commitment to the first assessment test. --- ...tructures Assessment Test-checkpoint.ipynb | 436 ++++++++++++++---- ... and Data Structures Assessment Test.ipynb | 436 ++++++++++++++---- 2 files changed, 680 insertions(+), 192 deletions(-) diff --git a/00-Python Object and Data Structure Basics/.ipynb_checkpoints/09-Objects and Data Structures Assessment Test-checkpoint.ipynb b/00-Python Object and Data Structure Basics/.ipynb_checkpoints/09-Objects and Data Structures Assessment Test-checkpoint.ipynb index 149e61af2..420643e3b 100644 --- a/00-Python Object and Data Structure Basics/.ipynb_checkpoints/09-Objects and Data Structures Assessment Test-checkpoint.ipynb +++ b/00-Python Object and Data Structure Basics/.ipynb_checkpoints/09-Objects and Data Structures Assessment Test-checkpoint.ipynb @@ -31,15 +31,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Numbers:\n", + "Numbers: Can store integer values (whole numbers) and floating point values (decimal numbers).\n", "\n", - "Strings:\n", + "Strings: Can store a sequence of characters, wich can be sorted at will, but are not changeble by index.\n", "\n", - "Lists:\n", + "Lists: Can store a sequence of any object type, wich can be sorted at will, but each value of the list can be treated separatly and modified at will.\n", "\n", - "Tuples:\n", + "Tuples: Can store a sequence of any object type, but cannot be sorted at will, and cannot be modified.\n", "\n", - "Dictionaries:\n" + "Dictionaries: Can store a sequence of values composed by any object type and it's respective key, facilitating the identification of each value, however the values cannot be sorted at will.\n" ] }, { @@ -55,10 +55,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "100.25" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(10**2)+(100-99.75)+(1*1/1)-1" + ] }, { "cell_type": "markdown", @@ -75,16 +88,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "34" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4+6*5" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "What is the *type* of the result of the expression 3 + 1.5 + 4?

" + "What is the *type* of the result of the expression 3 + 1.5 + 4? Float" ] }, { @@ -96,11 +122,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "# Square root:\n" + "# Square root:\n", + "number**(.5)" ] }, { @@ -109,7 +136,8 @@ "metadata": {}, "outputs": [], "source": [ - "# Square:\n" + "# Square:\n", + "number**(2)" ] }, { @@ -128,13 +156,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e\n" + ] + } + ], "source": [ "s = 'hello'\n", "# Print out 'e' using indexing\n", - "\n" + "\n", + "print(s[1])" ] }, { @@ -146,13 +183,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'olleh'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "s ='hello'\n", "# Reverse the string using slicing\n", - "\n" + "\n", + "s[::-1]" ] }, { @@ -164,25 +213,43 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "o\n" + ] + } + ], "source": [ "s ='hello'\n", "# Print out the 'o'\n", "\n", "# Method 1:\n", - "\n" + "\n", + "print(s[4])" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "o\n" + ] + } + ], "source": [ "# Method 2:\n", - "\n" + "\n", + "print(s[-1])" ] }, { @@ -201,20 +268,38 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 0, 0]\n" + ] + } + ], "source": [ - "# Method 1:\n" + "# Method 1:\n", + "print([0,0,0])" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 0, 0]\n" + ] + } + ], "source": [ - "# Method 2:\n" + "# Method 2:\n", + "print([0]*3)" ] }, { @@ -226,12 +311,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, [3, 4, 'goodbye']]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list3 = [1,2,[3,4,'hello']]\n", - "\n" + "\n", + "list3[2][2]='goodbye'\n", + "list3" ] }, { @@ -243,12 +341,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 3, 4, 5, 6]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list4 = [5,3,4,6,1]\n", - "\n" + "\n", + "list4.sort()\n", + "list4" ] }, { @@ -267,51 +378,101 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "d = {'simple_key':'hello'}\n", - "# Grab 'hello'\n" + "# Grab 'hello'\n", + "d['simple_key']" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "d = {'k1':{'k2':'hello'}}\n", - "# Grab 'hello'\n" + "# Grab 'hello'\n", + "d['k1']['k2']" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Getting a little tricker\n", "d = {'k1':[{'nest_key':['this is deep',['hello']]}]}\n", "\n", - "#Grab hello\n" + "#Grab hello\n", + "d['k1'][0]['nest_key'][1][0]" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# This will be hard and annoying!\n", - "d = {'k1':[1,2,{'k2':['this is tricky',{'tough':[1,2,['hello']]}]}]}" + "d = {'k1':[1,2,{'k2':['this is tricky',{'tough':[1,2,['hello']]}]}]}\n", + "d['k1'][2]['k2'][1]['tough'][2][0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Can you sort a dictionary? Why or why not?

" + "Can you sort a dictionary? Why or why not?\n", + "\n", + "No, because dictionaries have a key value mapping instead of a serial index like lists." ] }, { @@ -325,14 +486,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "What is the major difference between tuples and lists?

" + "What is the major difference between tuples and lists?\n", + "\n", + "Tuples cannot be modified." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "How do you create a tuple?

" + "How do you create a tuple?\n", + "\n", + "Using parentheses, ex: (1,2,3)." ] }, { @@ -346,7 +511,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "What is unique about a set?

" + "What is unique about a set?\n", + "\n", + "Values stored in sets are always unique." ] }, { @@ -358,13 +525,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3, 4, 11, 22, 33}" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list5 = [1,2,2,33,4,4,11,22,3,3,2]\n", "\n", - "\n" + "set(list5)" ] }, { @@ -426,52 +604,107 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "2 > 3" + "2 > 3 #false" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "3 <= 2" + "3 <= 2 #false" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "3 == 2.0" + "3 == 2.0 #false" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "3.0 == 3" + "3.0 == 3 #true" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "4**0.5 != 2" + "4**0.5 != 2 #false" ] }, { @@ -483,16 +716,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# two nested lists\n", "l_one = [1,2,[3,4]]\n", "l_two = [1,2,{'k1':4}]\n", "\n", "# True or False?\n", - "l_one[2][0] >= l_two[2]['k1']" + "l_one[2][0] >= l_two[2]['k1'] # 3 >= 4 false" ] }, { @@ -520,7 +764,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/00-Python Object and Data Structure Basics/09-Objects and Data Structures Assessment Test.ipynb b/00-Python Object and Data Structure Basics/09-Objects and Data Structures Assessment Test.ipynb index 149e61af2..420643e3b 100644 --- a/00-Python Object and Data Structure Basics/09-Objects and Data Structures Assessment Test.ipynb +++ b/00-Python Object and Data Structure Basics/09-Objects and Data Structures Assessment Test.ipynb @@ -31,15 +31,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Numbers:\n", + "Numbers: Can store integer values (whole numbers) and floating point values (decimal numbers).\n", "\n", - "Strings:\n", + "Strings: Can store a sequence of characters, wich can be sorted at will, but are not changeble by index.\n", "\n", - "Lists:\n", + "Lists: Can store a sequence of any object type, wich can be sorted at will, but each value of the list can be treated separatly and modified at will.\n", "\n", - "Tuples:\n", + "Tuples: Can store a sequence of any object type, but cannot be sorted at will, and cannot be modified.\n", "\n", - "Dictionaries:\n" + "Dictionaries: Can store a sequence of values composed by any object type and it's respective key, facilitating the identification of each value, however the values cannot be sorted at will.\n" ] }, { @@ -55,10 +55,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "100.25" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(10**2)+(100-99.75)+(1*1/1)-1" + ] }, { "cell_type": "markdown", @@ -75,16 +88,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "34" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4+6*5" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "What is the *type* of the result of the expression 3 + 1.5 + 4?

" + "What is the *type* of the result of the expression 3 + 1.5 + 4? Float" ] }, { @@ -96,11 +122,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "# Square root:\n" + "# Square root:\n", + "number**(.5)" ] }, { @@ -109,7 +136,8 @@ "metadata": {}, "outputs": [], "source": [ - "# Square:\n" + "# Square:\n", + "number**(2)" ] }, { @@ -128,13 +156,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e\n" + ] + } + ], "source": [ "s = 'hello'\n", "# Print out 'e' using indexing\n", - "\n" + "\n", + "print(s[1])" ] }, { @@ -146,13 +183,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'olleh'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "s ='hello'\n", "# Reverse the string using slicing\n", - "\n" + "\n", + "s[::-1]" ] }, { @@ -164,25 +213,43 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "o\n" + ] + } + ], "source": [ "s ='hello'\n", "# Print out the 'o'\n", "\n", "# Method 1:\n", - "\n" + "\n", + "print(s[4])" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "o\n" + ] + } + ], "source": [ "# Method 2:\n", - "\n" + "\n", + "print(s[-1])" ] }, { @@ -201,20 +268,38 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 0, 0]\n" + ] + } + ], "source": [ - "# Method 1:\n" + "# Method 1:\n", + "print([0,0,0])" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 0, 0]\n" + ] + } + ], "source": [ - "# Method 2:\n" + "# Method 2:\n", + "print([0]*3)" ] }, { @@ -226,12 +311,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, [3, 4, 'goodbye']]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list3 = [1,2,[3,4,'hello']]\n", - "\n" + "\n", + "list3[2][2]='goodbye'\n", + "list3" ] }, { @@ -243,12 +341,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 3, 4, 5, 6]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list4 = [5,3,4,6,1]\n", - "\n" + "\n", + "list4.sort()\n", + "list4" ] }, { @@ -267,51 +378,101 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "d = {'simple_key':'hello'}\n", - "# Grab 'hello'\n" + "# Grab 'hello'\n", + "d['simple_key']" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "d = {'k1':{'k2':'hello'}}\n", - "# Grab 'hello'\n" + "# Grab 'hello'\n", + "d['k1']['k2']" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Getting a little tricker\n", "d = {'k1':[{'nest_key':['this is deep',['hello']]}]}\n", "\n", - "#Grab hello\n" + "#Grab hello\n", + "d['k1'][0]['nest_key'][1][0]" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# This will be hard and annoying!\n", - "d = {'k1':[1,2,{'k2':['this is tricky',{'tough':[1,2,['hello']]}]}]}" + "d = {'k1':[1,2,{'k2':['this is tricky',{'tough':[1,2,['hello']]}]}]}\n", + "d['k1'][2]['k2'][1]['tough'][2][0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Can you sort a dictionary? Why or why not?

" + "Can you sort a dictionary? Why or why not?\n", + "\n", + "No, because dictionaries have a key value mapping instead of a serial index like lists." ] }, { @@ -325,14 +486,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "What is the major difference between tuples and lists?

" + "What is the major difference between tuples and lists?\n", + "\n", + "Tuples cannot be modified." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "How do you create a tuple?

" + "How do you create a tuple?\n", + "\n", + "Using parentheses, ex: (1,2,3)." ] }, { @@ -346,7 +511,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "What is unique about a set?

" + "What is unique about a set?\n", + "\n", + "Values stored in sets are always unique." ] }, { @@ -358,13 +525,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3, 4, 11, 22, 33}" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list5 = [1,2,2,33,4,4,11,22,3,3,2]\n", "\n", - "\n" + "set(list5)" ] }, { @@ -426,52 +604,107 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "2 > 3" + "2 > 3 #false" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "3 <= 2" + "3 <= 2 #false" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "3 == 2.0" + "3 == 2.0 #false" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "3.0 == 3" + "3.0 == 3 #true" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Answer before running cell\n", - "4**0.5 != 2" + "4**0.5 != 2 #false" ] }, { @@ -483,16 +716,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# two nested lists\n", "l_one = [1,2,[3,4]]\n", "l_two = [1,2,{'k1':4}]\n", "\n", "# True or False?\n", - "l_one[2][0] >= l_two[2]['k1']" + "l_one[2][0] >= l_two[2]['k1'] # 3 >= 4 false" ] }, { @@ -520,7 +764,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, From 4df7e39682eb557ec0fc1ea2748a879f7a2488cd Mon Sep 17 00:00:00 2001 From: Leonardo Santos Date: Sat, 21 Apr 2018 17:57:49 -0300 Subject: [PATCH 2/6] My commitment to the second assessment test. --- ...tatements Assessment Test-checkpoint.ipynb | 245 ++++++++++++++---- .../07-Statements Assessment Test.ipynb | 222 ++++++++++++++-- 2 files changed, 399 insertions(+), 68 deletions(-) diff --git a/02-Python Statements/.ipynb_checkpoints/07-Statements Assessment Test-checkpoint.ipynb b/02-Python Statements/.ipynb_checkpoints/07-Statements Assessment Test-checkpoint.ipynb index 4d9ee290f..2409e4355 100644 --- a/02-Python Statements/.ipynb_checkpoints/07-Statements Assessment Test-checkpoint.ipynb +++ b/02-Python Statements/.ipynb_checkpoints/07-Statements Assessment Test-checkpoint.ipynb @@ -20,10 +20,8 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": true - }, + "execution_count": 2, + "metadata": {}, "outputs": [], "source": [ "st = 'Print only the words that start with s in this sentence'" @@ -31,11 +29,23 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "start\n", + "s\n", + "sentence\n" + ] + } + ], "source": [ - "#Code here" + "for item in st.split():\n", + " if item[0] == 's':\n", + " print(item)" ] }, { @@ -48,11 +58,25 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n", + "6\n", + "8\n", + "10\n" + ] + } + ], "source": [ - "#Code Here" + "for num in range(0,11,2):\n", + " print(num)" ] }, { @@ -65,23 +89,20 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 17, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]\n" + ] } ], "source": [ - "#Code in this cell\n", - "[]" + "mylist = [num for num in range(1,51) if num%3==0]\n", + "print(mylist)" ] }, { @@ -94,10 +115,8 @@ }, { "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": true - }, + "execution_count": 13, + "metadata": {}, "outputs": [], "source": [ "st = 'Print every word in this sentence that has an even number of letters'" @@ -105,13 +124,29 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n" + ] + } + ], "source": [ - "#Code in this cell" + "for item in st.split():\n", + " if len(item)%2 == 0:\n", + " print('even!')" ] }, { @@ -124,11 +159,126 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "Fizz\n", + "4\n", + "Buzz\n", + "Fizz\n", + "7\n", + "8\n", + "Fizz\n", + "Buzz\n", + "11\n", + "Fizz\n", + "13\n", + "14\n", + "FizzBuzz\n", + "16\n", + "17\n", + "Fizz\n", + "19\n", + "Buzz\n", + "Fizz\n", + "22\n", + "23\n", + "Fizz\n", + "Buzz\n", + "26\n", + "Fizz\n", + "28\n", + "29\n", + "FizzBuzz\n", + "31\n", + "32\n", + "Fizz\n", + "34\n", + "Buzz\n", + "Fizz\n", + "37\n", + "38\n", + "Fizz\n", + "Buzz\n", + "41\n", + "Fizz\n", + "43\n", + "44\n", + "FizzBuzz\n", + "46\n", + "47\n", + "Fizz\n", + "49\n", + "Buzz\n", + "Fizz\n", + "52\n", + "53\n", + "Fizz\n", + "Buzz\n", + "56\n", + "Fizz\n", + "58\n", + "59\n", + "FizzBuzz\n", + "61\n", + "62\n", + "Fizz\n", + "64\n", + "Buzz\n", + "Fizz\n", + "67\n", + "68\n", + "Fizz\n", + "Buzz\n", + "71\n", + "Fizz\n", + "73\n", + "74\n", + "FizzBuzz\n", + "76\n", + "77\n", + "Fizz\n", + "79\n", + "Buzz\n", + "Fizz\n", + "82\n", + "83\n", + "Fizz\n", + "Buzz\n", + "86\n", + "Fizz\n", + "88\n", + "89\n", + "FizzBuzz\n", + "91\n", + "92\n", + "Fizz\n", + "94\n", + "Buzz\n", + "Fizz\n", + "97\n", + "98\n", + "Fizz\n", + "Buzz\n" + ] + } + ], "source": [ - "#Code in this cell" + "for item in range(1,101):\n", + " if item%3==0 and item%5!=0:\n", + " print('Fizz')\n", + " elif item%5==0 and item%3!=0:\n", + " print('Buzz')\n", + " elif item%3==0 and item%5==0:\n", + " print('FizzBuzz')\n", + " else:\n", + " print(item)" ] }, { @@ -141,10 +291,8 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": { - "collapsed": true - }, + "execution_count": 24, + "metadata": {}, "outputs": [], "source": [ "st = 'Create a list of the first letters of every word in this string'" @@ -152,13 +300,20 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['C', 'a', 'l', 'o', 't', 'f', 'l', 'o', 'e', 'w', 'i', 't', 's']\n" + ] + } + ], "source": [ - "#Code in this cell" + "firstletters = [letter[0] for letter in st.split()]\n", + "print(firstletters)" ] }, { @@ -185,7 +340,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/02-Python Statements/07-Statements Assessment Test.ipynb b/02-Python Statements/07-Statements Assessment Test.ipynb index b9e545460..2409e4355 100644 --- a/02-Python Statements/07-Statements Assessment Test.ipynb +++ b/02-Python Statements/07-Statements Assessment Test.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -29,11 +29,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "start\n", + "s\n", + "sentence\n" + ] + } + ], "source": [ - "#Code here" + "for item in st.split():\n", + " if item[0] == 's':\n", + " print(item)" ] }, { @@ -46,11 +58,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n", + "6\n", + "8\n", + "10\n" + ] + } + ], "source": [ - "#Code Here" + "for num in range(0,11,2):\n", + " print(num)" ] }, { @@ -63,12 +89,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]\n" + ] + } + ], "source": [ - "#Code in this cell\n", - "[]" + "mylist = [num for num in range(1,51) if num%3==0]\n", + "print(mylist)" ] }, { @@ -81,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -90,11 +124,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n", + "even!\n" + ] + } + ], "source": [ - "#Code in this cell" + "for item in st.split():\n", + " if len(item)%2 == 0:\n", + " print('even!')" ] }, { @@ -107,11 +159,126 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "Fizz\n", + "4\n", + "Buzz\n", + "Fizz\n", + "7\n", + "8\n", + "Fizz\n", + "Buzz\n", + "11\n", + "Fizz\n", + "13\n", + "14\n", + "FizzBuzz\n", + "16\n", + "17\n", + "Fizz\n", + "19\n", + "Buzz\n", + "Fizz\n", + "22\n", + "23\n", + "Fizz\n", + "Buzz\n", + "26\n", + "Fizz\n", + "28\n", + "29\n", + "FizzBuzz\n", + "31\n", + "32\n", + "Fizz\n", + "34\n", + "Buzz\n", + "Fizz\n", + "37\n", + "38\n", + "Fizz\n", + "Buzz\n", + "41\n", + "Fizz\n", + "43\n", + "44\n", + "FizzBuzz\n", + "46\n", + "47\n", + "Fizz\n", + "49\n", + "Buzz\n", + "Fizz\n", + "52\n", + "53\n", + "Fizz\n", + "Buzz\n", + "56\n", + "Fizz\n", + "58\n", + "59\n", + "FizzBuzz\n", + "61\n", + "62\n", + "Fizz\n", + "64\n", + "Buzz\n", + "Fizz\n", + "67\n", + "68\n", + "Fizz\n", + "Buzz\n", + "71\n", + "Fizz\n", + "73\n", + "74\n", + "FizzBuzz\n", + "76\n", + "77\n", + "Fizz\n", + "79\n", + "Buzz\n", + "Fizz\n", + "82\n", + "83\n", + "Fizz\n", + "Buzz\n", + "86\n", + "Fizz\n", + "88\n", + "89\n", + "FizzBuzz\n", + "91\n", + "92\n", + "Fizz\n", + "94\n", + "Buzz\n", + "Fizz\n", + "97\n", + "98\n", + "Fizz\n", + "Buzz\n" + ] + } + ], "source": [ - "#Code in this cell" + "for item in range(1,101):\n", + " if item%3==0 and item%5!=0:\n", + " print('Fizz')\n", + " elif item%5==0 and item%3!=0:\n", + " print('Buzz')\n", + " elif item%3==0 and item%5==0:\n", + " print('FizzBuzz')\n", + " else:\n", + " print(item)" ] }, { @@ -124,7 +291,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -133,11 +300,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['C', 'a', 'l', 'o', 't', 'f', 'l', 'o', 'e', 'w', 'i', 't', 's']\n" + ] + } + ], "source": [ - "#Code in this cell" + "firstletters = [letter[0] for letter in st.split()]\n", + "print(firstletters)" ] }, { @@ -164,7 +340,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, From b6da961987f77a5a3bb3307cde0631cdc29c0987 Mon Sep 17 00:00:00 2001 From: Leonardo Santos Date: Sat, 21 Apr 2018 23:21:15 -0300 Subject: [PATCH 3/6] My commitment to the function practice exercises. --- ...nction Practice Exercises-checkpoint.ipynb | 686 +++++++++++++----- .../03-Function Practice Exercises.ipynb | 686 +++++++++++++----- 2 files changed, 978 insertions(+), 394 deletions(-) diff --git a/03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb b/03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb index cb906dbe6..2121af489 100644 --- a/03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb +++ b/03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb @@ -31,23 +31,37 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 1, + "metadata": {}, "outputs": [], "source": [ "def lesser_of_two_evens(a,b):\n", - " pass" + " if a%2 == 0 and b%2 == 0 and a>b:\n", + " return b\n", + " elif a%2 == 0 and b%2 == 0 and a0:\n", + " cont += 1\n", + " else:\n", + " continue\n", + " if cont == 0:\n", + " return False\n", + " else:\n", + " return True" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "has_33([1, 3, 3])" @@ -363,9 +500,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "has_33([1, 3, 1, 3])" @@ -373,9 +521,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "has_33([3, 1, 3])" @@ -392,23 +551,33 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 36, + "metadata": {}, "outputs": [], "source": [ "def paper_doll(text):\n", - " pass" + " mystring = \"\"\n", + " for a,b in enumerate(text):\n", + " mystring += text[a]*3\n", + " return mystring" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'HHHeeellllllooo'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "paper_doll('Hello')" @@ -416,11 +585,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'MMMiiissssssiiissssssiiippppppiii'" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "paper_doll('Mississippi')" @@ -438,23 +616,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 41, + "metadata": {}, "outputs": [], "source": [ "def blackjack(a,b,c):\n", - " pass" + " result = a+b+c\n", + " if a==11 or b==11 or c==11:\n", + " result -= 10\n", + " if result > 21:\n", + " return 'BUST'\n", + " else:\n", + " return result" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "blackjack(5,6,7)" @@ -462,11 +653,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'BUST'" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "blackjack(9,9,9)" @@ -474,11 +674,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "19" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "blackjack(9,9,11)" @@ -497,23 +706,45 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 60, + "metadata": {}, "outputs": [], "source": [ "def summer_69(arr):\n", - " pass" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + " result = 0\n", + " temp = True\n", + " for item in arr:\n", + " while temp:\n", + " if item != 6:\n", + " result += item\n", + " break\n", + " else:\n", + " temp = False\n", + " while not temp:\n", + " if item !=9:\n", + " break\n", + " else:\n", + " temp=True\n", + " break\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "summer_69([1, 3, 5])" @@ -521,11 +752,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "summer_69([4, 5, 6, 7, 8, 9])" @@ -533,11 +773,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "summer_69([2, 1, 6, 9, 11])" @@ -563,23 +812,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 74, + "metadata": {}, "outputs": [], "source": [ "def spy_game(nums):\n", - " pass" + " \n", + " for a,b in enumerate(nums):\n", + " if a > 2 and nums[a] == 7 and nums[a-1] == 0 and nums[a-2] == 0:\n", + " return True\n", + " return False" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "spy_game([1,2,4,0,0,7,5])" @@ -587,11 +847,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "spy_game([1,0,2,4,0,5,7])" @@ -599,11 +868,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "spy_game([1,7,2,0,4,5,0])" @@ -621,24 +899,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 78, + "metadata": {}, "outputs": [], "source": [ "def count_primes(num):\n", - " pass\n", - " " + " cont = 0\n", + " for item in range(0,num):\n", + " if item%2!=0 and item%3!=0 and item%4!=0 and item%5!=0 and item%6!=0 and item%7!=0 and item%8!=0 and item%9!=0:\n", + " cont += 1\n", + " else:\n", + " continue\n", + " return cont" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "22" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "count_primes(100)" @@ -669,7 +959,9 @@ "outputs": [], "source": [ "def print_big(letter):\n", - " pass" + " pass\n", + "\n", + " #i'm passing this one sry..." ] }, { @@ -707,7 +999,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/03-Methods and Functions/03-Function Practice Exercises.ipynb b/03-Methods and Functions/03-Function Practice Exercises.ipynb index cb906dbe6..2121af489 100644 --- a/03-Methods and Functions/03-Function Practice Exercises.ipynb +++ b/03-Methods and Functions/03-Function Practice Exercises.ipynb @@ -31,23 +31,37 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 1, + "metadata": {}, "outputs": [], "source": [ "def lesser_of_two_evens(a,b):\n", - " pass" + " if a%2 == 0 and b%2 == 0 and a>b:\n", + " return b\n", + " elif a%2 == 0 and b%2 == 0 and a0:\n", + " cont += 1\n", + " else:\n", + " continue\n", + " if cont == 0:\n", + " return False\n", + " else:\n", + " return True" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "has_33([1, 3, 3])" @@ -363,9 +500,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "has_33([1, 3, 1, 3])" @@ -373,9 +521,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "has_33([3, 1, 3])" @@ -392,23 +551,33 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 36, + "metadata": {}, "outputs": [], "source": [ "def paper_doll(text):\n", - " pass" + " mystring = \"\"\n", + " for a,b in enumerate(text):\n", + " mystring += text[a]*3\n", + " return mystring" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'HHHeeellllllooo'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "paper_doll('Hello')" @@ -416,11 +585,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'MMMiiissssssiiissssssiiippppppiii'" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "paper_doll('Mississippi')" @@ -438,23 +616,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 41, + "metadata": {}, "outputs": [], "source": [ "def blackjack(a,b,c):\n", - " pass" + " result = a+b+c\n", + " if a==11 or b==11 or c==11:\n", + " result -= 10\n", + " if result > 21:\n", + " return 'BUST'\n", + " else:\n", + " return result" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "blackjack(5,6,7)" @@ -462,11 +653,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'BUST'" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "blackjack(9,9,9)" @@ -474,11 +674,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "19" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "blackjack(9,9,11)" @@ -497,23 +706,45 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 60, + "metadata": {}, "outputs": [], "source": [ "def summer_69(arr):\n", - " pass" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + " result = 0\n", + " temp = True\n", + " for item in arr:\n", + " while temp:\n", + " if item != 6:\n", + " result += item\n", + " break\n", + " else:\n", + " temp = False\n", + " while not temp:\n", + " if item !=9:\n", + " break\n", + " else:\n", + " temp=True\n", + " break\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "summer_69([1, 3, 5])" @@ -521,11 +752,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "summer_69([4, 5, 6, 7, 8, 9])" @@ -533,11 +773,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "summer_69([2, 1, 6, 9, 11])" @@ -563,23 +812,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 74, + "metadata": {}, "outputs": [], "source": [ "def spy_game(nums):\n", - " pass" + " \n", + " for a,b in enumerate(nums):\n", + " if a > 2 and nums[a] == 7 and nums[a-1] == 0 and nums[a-2] == 0:\n", + " return True\n", + " return False" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "spy_game([1,2,4,0,0,7,5])" @@ -587,11 +847,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "spy_game([1,0,2,4,0,5,7])" @@ -599,11 +868,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "spy_game([1,7,2,0,4,5,0])" @@ -621,24 +899,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 78, + "metadata": {}, "outputs": [], "source": [ "def count_primes(num):\n", - " pass\n", - " " + " cont = 0\n", + " for item in range(0,num):\n", + " if item%2!=0 and item%3!=0 and item%4!=0 and item%5!=0 and item%6!=0 and item%7!=0 and item%8!=0 and item%9!=0:\n", + " cont += 1\n", + " else:\n", + " continue\n", + " return cont" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "22" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Check\n", "count_primes(100)" @@ -669,7 +959,9 @@ "outputs": [], "source": [ "def print_big(letter):\n", - " pass" + " pass\n", + "\n", + " #i'm passing this one sry..." ] }, { @@ -707,7 +999,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, From 4d75055a904965d0d3e678c015a4cb4b19d9afd1 Mon Sep 17 00:00:00 2001 From: Leonardo Santos Date: Mon, 23 Apr 2018 14:48:58 -0300 Subject: [PATCH 4/6] My commitment to the functions and methods homework. --- ...ions and Methods Homework-checkpoint.ipynb | 428 ++++++++++++++++++ .../08-Functions and Methods Homework.ipynb | 100 ++-- 2 files changed, 499 insertions(+), 29 deletions(-) create mode 100644 03-Methods and Functions/.ipynb_checkpoints/08-Functions and Methods Homework-checkpoint.ipynb diff --git a/03-Methods and Functions/.ipynb_checkpoints/08-Functions and Methods Homework-checkpoint.ipynb b/03-Methods and Functions/.ipynb_checkpoints/08-Functions and Methods Homework-checkpoint.ipynb new file mode 100644 index 000000000..303f9b794 --- /dev/null +++ b/03-Methods and Functions/.ipynb_checkpoints/08-Functions and Methods Homework-checkpoint.ipynb @@ -0,0 +1,428 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Functions and Methods Homework \n", + "\n", + "Complete the following questions:\n", + "____\n", + "**Write a function that computes the volume of a sphere given its radius.**\n", + "

The volume of a sphere is given as $$\\frac{4}{3} πr^3$$

" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "\n", + "def vol(rad):\n", + " result = (4/3)*math.pi*(rad**3)\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "33.510321638291124" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Check\n", + "vol(2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___\n", + "**Write a function that checks whether a number is in a given range (inclusive of high and low)**" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def ran_check(num,low,high):\n", + " if low < num < high:\n", + " print(f'{num} is in the range between {low} and {high}')\n", + " else:\n", + " print(f\"{num} isn't in the range between {low} and {high}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5 is in the range between 2 and 7\n" + ] + } + ], + "source": [ + "# Check\n", + "ran_check(5,2,7)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you only wanted to return a boolean:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def ran_bool(num,low,high):\n", + " if low < num < high:\n", + " return True\n", + " else:\n", + " return False" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ran_bool(3,1,10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____\n", + "**Write a Python function that accepts a string and calculates the number of upper case letters and lower case letters.**\n", + "\n", + " Sample String : 'Hello Mr. Rogers, how are you this fine Tuesday?'\n", + " Expected Output : \n", + " No. of Upper case characters : 4\n", + " No. of Lower case Characters : 33\n", + "\n", + "HINT: Two string methods that might prove useful: **.isupper()** and **.islower()**\n", + "\n", + "If you feel ambitious, explore the Collections module to solve this problem!" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "def up_low(s):\n", + " cont_upper = 0\n", + " cont_lower = 0\n", + " for a,b in enumerate(s):\n", + " if s[a].isupper():\n", + " cont_upper += 1\n", + " elif s[a].islower():\n", + " cont_lower += 1\n", + " print(f'No. of Upper case characters : {cont_upper}')\n", + " print(f'No. of Lower case Characters : {cont_lower}')" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No. of Upper case characters : 4\n", + "No. of Lower case Characters : 33\n" + ] + } + ], + "source": [ + "s = 'Hello Mr. Rogers, how are you this fine Tuesday?'\n", + "up_low(s)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____\n", + "**Write a Python function that takes a list and returns a new list with unique elements of the first list.**\n", + "\n", + " Sample List : [1,1,1,1,2,2,3,3,3,3,4,5]\n", + " Unique List : [1, 2, 3, 4, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "def unique_list(lst):\n", + " new_list = [lst[0]]\n", + " temp = lst[0]\n", + " for a,b in enumerate(lst):\n", + " if temp == lst[a]:\n", + " continue\n", + " else:\n", + " new_list.append(lst[a])\n", + " temp = lst[a]\n", + " return new_list" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "unique_list([1,1,1,1,2,2,3,3,3,3,4,5])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____\n", + "**Write a Python function to multiply all the numbers in a list.**\n", + "\n", + " Sample List : [1, 2, 3, -4]\n", + " Expected Output : -24" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "def multiply(numbers): \n", + " result = 1\n", + " for a,b in enumerate(numbers):\n", + " result *= numbers[a]\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-24" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "multiply([1,2,3,-4])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____\n", + "**Write a Python function that checks whether a passed in string is palindrome or not.**\n", + "\n", + "Note: A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run." + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "def palindrome(s):\n", + " if s[::] == s[::-1]:\n", + " return True\n", + " else:\n", + " return False" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "palindrome('helleh')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____\n", + "#### Hard:\n", + "\n", + "**Write a Python function to check whether a string is pangram or not.**\n", + "\n", + " Note : Pangrams are words or sentences containing every letter of the alphabet at least once.\n", + " For example : \"The quick brown fox jumps over the lazy dog\"\n", + "\n", + "Hint: Look at the string module" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "import string\n", + "\n", + "def ispangram(str1, alphabet=string.ascii_lowercase):\n", + " \n", + " cont = 0\n", + " \n", + " for a,b in enumerate(alphabet):\n", + " for x,y in enumerate(str1):\n", + " if alphabet[a] == str1[x]:\n", + " cont += 1\n", + " else:\n", + " continue\n", + " if cont >= 26:\n", + " return True\n", + " else:\n", + " return False" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ispangram(\"The quick brown fox jumps over the lazy dog\")" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'abcdefghijklmnopqrstuvwxyz'" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "string.ascii_lowercase" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "#### Great Job!" + ] + } + ], + "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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/03-Methods and Functions/08-Functions and Methods Homework.ipynb b/03-Methods and Functions/08-Functions and Methods Homework.ipynb index 95d610956..303f9b794 100644 --- a/03-Methods and Functions/08-Functions and Methods Homework.ipynb +++ b/03-Methods and Functions/08-Functions and Methods Homework.ipynb @@ -18,8 +18,11 @@ "metadata": {}, "outputs": [], "source": [ + "import math\n", + "\n", "def vol(rad):\n", - " pass" + " result = (4/3)*math.pi*(rad**3)\n", + " return result" ] }, { @@ -30,7 +33,7 @@ { "data": { "text/plain": [ - "33.49333333333333" + "33.510321638291124" ] }, "execution_count": 2, @@ -58,7 +61,10 @@ "outputs": [], "source": [ "def ran_check(num,low,high):\n", - " pass" + " if low < num < high:\n", + " print(f'{num} is in the range between {low} and {high}')\n", + " else:\n", + " print(f\"{num} isn't in the range between {low} and {high}\")" ] }, { @@ -93,7 +99,10 @@ "outputs": [], "source": [ "def ran_bool(num,low,high):\n", - " pass" + " if low < num < high:\n", + " return True\n", + " else:\n", + " return False" ] }, { @@ -135,26 +144,33 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "def up_low(s):\n", - " pass" + " cont_upper = 0\n", + " cont_lower = 0\n", + " for a,b in enumerate(s):\n", + " if s[a].isupper():\n", + " cont_upper += 1\n", + " elif s[a].islower():\n", + " cont_lower += 1\n", + " print(f'No. of Upper case characters : {cont_upper}')\n", + " print(f'No. of Lower case Characters : {cont_lower}')" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Original String : Hello Mr. Rogers, how are you this fine Tuesday?\n", - "No. of Upper case characters : 4\n", - "No. of Lower case Characters : 33\n" + "No. of Upper case characters : 4\n", + "No. of Lower case Characters : 33\n" ] } ], @@ -176,17 +192,25 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "def unique_list(lst):\n", - " pass" + " new_list = [lst[0]]\n", + " temp = lst[0]\n", + " for a,b in enumerate(lst):\n", + " if temp == lst[a]:\n", + " continue\n", + " else:\n", + " new_list.append(lst[a])\n", + " temp = lst[a]\n", + " return new_list" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -195,7 +219,7 @@ "[1, 2, 3, 4, 5]" ] }, - "execution_count": 10, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -217,17 +241,20 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "def multiply(numbers): \n", - " pass" + " result = 1\n", + " for a,b in enumerate(numbers):\n", + " result *= numbers[a]\n", + " return result" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -236,7 +263,7 @@ "-24" ] }, - "execution_count": 12, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -257,17 +284,20 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "def palindrome(s):\n", - " pass" + " if s[::] == s[::-1]:\n", + " return True\n", + " else:\n", + " return False" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -276,7 +306,7 @@ "True" ] }, - "execution_count": 14, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -302,19 +332,31 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "import string\n", "\n", "def ispangram(str1, alphabet=string.ascii_lowercase):\n", - " pass" + " \n", + " cont = 0\n", + " \n", + " for a,b in enumerate(alphabet):\n", + " for x,y in enumerate(str1):\n", + " if alphabet[a] == str1[x]:\n", + " cont += 1\n", + " else:\n", + " continue\n", + " if cont >= 26:\n", + " return True\n", + " else:\n", + " return False" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -323,7 +365,7 @@ "True" ] }, - "execution_count": 16, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -334,7 +376,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -343,7 +385,7 @@ "'abcdefghijklmnopqrstuvwxyz'" ] }, - "execution_count": 17, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -378,7 +420,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, From df40416ff830c8093a76c9856fbdbbe26913542d Mon Sep 17 00:00:00 2001 From: Leonardo Santos Date: Tue, 24 Apr 2018 01:27:03 -0300 Subject: [PATCH 5/6] My commitment to the object oriented programming homework --- ...nted Programming Homework-checkpoint.ipynb | 55 ++++++++++++------- ...Object Oriented Programming Homework.ipynb | 55 ++++++++++++------- 2 files changed, 68 insertions(+), 42 deletions(-) diff --git a/05-Object Oriented Programming/.ipynb_checkpoints/02-Object Oriented Programming Homework-checkpoint.ipynb b/05-Object Oriented Programming/.ipynb_checkpoints/02-Object Oriented Programming Homework-checkpoint.ipynb index 3824be7be..020fa405f 100644 --- a/05-Object Oriented Programming/.ipynb_checkpoints/02-Object Oriented Programming Homework-checkpoint.ipynb +++ b/05-Object Oriented Programming/.ipynb_checkpoints/02-Object Oriented Programming Homework-checkpoint.ipynb @@ -13,25 +13,28 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ + "import math\n", + "\n", "class Line:\n", " \n", " def __init__(self,coor1,coor2):\n", - " pass\n", + " self.coor1 = coor1\n", + " self.coor2 = coor2\n", " \n", " def distance(self):\n", - " pass\n", + " return math.sqrt(((self.coor2[0]-self.coor1[0])**2) + ((self.coor2[1]-self.coor1[1])**2))\n", " \n", " def slope(self):\n", - " pass" + " return (self.coor2[1]-self.coor1[1])/(self.coor2[0]-self.coor1[0])" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -45,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -54,7 +57,7 @@ "9.433981132056603" ] }, - "execution_count": 3, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -65,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -74,7 +77,7 @@ "1.6" ] }, - "execution_count": 4, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -100,25 +103,28 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ + "import math\n", + "\n", "class Cylinder:\n", " \n", " def __init__(self,height=1,radius=1):\n", - " pass\n", + " self.height = height\n", + " self.radius = radius\n", " \n", " def volume(self):\n", - " pass\n", + " return (math.pi*(self.radius**2))*self.height\n", " \n", " def surface_area(self):\n", - " pass" + " return ((math.pi*(self.radius**2)*2)+((2*math.pi*self.radius)*self.height))" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -128,16 +134,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "56.52" + "56.548667764616276" ] }, - "execution_count": 7, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -148,16 +154,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "94.2" + "94.24777960769379" ] }, - "execution_count": 8, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -165,6 +171,13 @@ "source": [ "c.surface_area()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -183,7 +196,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/05-Object Oriented Programming/02-Object Oriented Programming Homework.ipynb b/05-Object Oriented Programming/02-Object Oriented Programming Homework.ipynb index 3824be7be..020fa405f 100644 --- a/05-Object Oriented Programming/02-Object Oriented Programming Homework.ipynb +++ b/05-Object Oriented Programming/02-Object Oriented Programming Homework.ipynb @@ -13,25 +13,28 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ + "import math\n", + "\n", "class Line:\n", " \n", " def __init__(self,coor1,coor2):\n", - " pass\n", + " self.coor1 = coor1\n", + " self.coor2 = coor2\n", " \n", " def distance(self):\n", - " pass\n", + " return math.sqrt(((self.coor2[0]-self.coor1[0])**2) + ((self.coor2[1]-self.coor1[1])**2))\n", " \n", " def slope(self):\n", - " pass" + " return (self.coor2[1]-self.coor1[1])/(self.coor2[0]-self.coor1[0])" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -45,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -54,7 +57,7 @@ "9.433981132056603" ] }, - "execution_count": 3, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -65,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -74,7 +77,7 @@ "1.6" ] }, - "execution_count": 4, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -100,25 +103,28 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ + "import math\n", + "\n", "class Cylinder:\n", " \n", " def __init__(self,height=1,radius=1):\n", - " pass\n", + " self.height = height\n", + " self.radius = radius\n", " \n", " def volume(self):\n", - " pass\n", + " return (math.pi*(self.radius**2))*self.height\n", " \n", " def surface_area(self):\n", - " pass" + " return ((math.pi*(self.radius**2)*2)+((2*math.pi*self.radius)*self.height))" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -128,16 +134,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "56.52" + "56.548667764616276" ] }, - "execution_count": 7, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -148,16 +154,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "94.2" + "94.24777960769379" ] }, - "execution_count": 8, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -165,6 +171,13 @@ "source": [ "c.surface_area()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -183,7 +196,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, From 35dbcda7e665a944666092d816ccfb6651929cc4 Mon Sep 17 00:00:00 2001 From: Leonardo Santos Date: Tue, 24 Apr 2018 08:52:51 -0300 Subject: [PATCH 6/6] My commitment to the OOP Challenge. --- .../04-OOP Challenge-checkpoint.ipynb | 59 +++++++++++-------- .../04-OOP Challenge.ipynb | 59 +++++++++++-------- 2 files changed, 70 insertions(+), 48 deletions(-) diff --git a/05-Object Oriented Programming/.ipynb_checkpoints/04-OOP Challenge-checkpoint.ipynb b/05-Object Oriented Programming/.ipynb_checkpoints/04-OOP Challenge-checkpoint.ipynb index fb60ffb74..6b92e603b 100644 --- a/05-Object Oriented Programming/.ipynb_checkpoints/04-OOP Challenge-checkpoint.ipynb +++ b/05-Object Oriented Programming/.ipynb_checkpoints/04-OOP Challenge-checkpoint.ipynb @@ -23,17 +23,36 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "class Account:\n", - " pass" + " \n", + " def __init__(self, owner, balance):\n", + " self.owner = owner\n", + " self.balance = balance\n", + " \n", + " def deposit(self, amount):\n", + " if amount > 0:\n", + " self.balance = self.balance + amount\n", + " else:\n", + " print('Invalid amount.')\n", + " \n", + " def withdraw(self, amount):\n", + " if amount > self.balance:\n", + " print('You cannot withdraw more than your current account balance.')\n", + " else:\n", + " self.balance = self.balance - amount\n", + " print('Withdraw Accepted')\n", + " \n", + " def __str__(self):\n", + " return f'Account owner: {self.owner}\\nAccount balance: ${self.balance}'" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -43,14 +62,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Account owner: Jose\n", + "Account owner: Jose\n", "Account balance: $100\n" ] } @@ -62,7 +81,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -71,7 +90,7 @@ "'Jose'" ] }, - "execution_count": 4, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -83,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -92,7 +111,7 @@ "100" ] }, - "execution_count": 5, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -104,17 +123,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 27, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Deposit Accepted\n" - ] - } - ], + "outputs": [], "source": [ "# 5. Make a series of deposits and withdrawals\n", "acct1.deposit(50)" @@ -122,14 +133,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Withdrawal Accepted\n" + "Withdraw Accepted\n" ] } ], @@ -139,14 +150,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Funds Unavailable!\n" + "You cannot withdraw more than your current account balance.\n" ] } ], @@ -179,7 +190,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/05-Object Oriented Programming/04-OOP Challenge.ipynb b/05-Object Oriented Programming/04-OOP Challenge.ipynb index fb60ffb74..6b92e603b 100644 --- a/05-Object Oriented Programming/04-OOP Challenge.ipynb +++ b/05-Object Oriented Programming/04-OOP Challenge.ipynb @@ -23,17 +23,36 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "class Account:\n", - " pass" + " \n", + " def __init__(self, owner, balance):\n", + " self.owner = owner\n", + " self.balance = balance\n", + " \n", + " def deposit(self, amount):\n", + " if amount > 0:\n", + " self.balance = self.balance + amount\n", + " else:\n", + " print('Invalid amount.')\n", + " \n", + " def withdraw(self, amount):\n", + " if amount > self.balance:\n", + " print('You cannot withdraw more than your current account balance.')\n", + " else:\n", + " self.balance = self.balance - amount\n", + " print('Withdraw Accepted')\n", + " \n", + " def __str__(self):\n", + " return f'Account owner: {self.owner}\\nAccount balance: ${self.balance}'" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -43,14 +62,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Account owner: Jose\n", + "Account owner: Jose\n", "Account balance: $100\n" ] } @@ -62,7 +81,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -71,7 +90,7 @@ "'Jose'" ] }, - "execution_count": 4, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -83,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -92,7 +111,7 @@ "100" ] }, - "execution_count": 5, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -104,17 +123,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 27, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Deposit Accepted\n" - ] - } - ], + "outputs": [], "source": [ "# 5. Make a series of deposits and withdrawals\n", "acct1.deposit(50)" @@ -122,14 +133,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Withdrawal Accepted\n" + "Withdraw Accepted\n" ] } ], @@ -139,14 +150,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Funds Unavailable!\n" + "You cannot withdraw more than your current account balance.\n" ] } ], @@ -179,7 +190,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4,