From de50282549015a52e760a2fc6f47fac7eadbd649 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 18:52:36 -0500 Subject: [PATCH 01/10] Add files via upload --- Section_02/assignment_01.py | 17 ++++++---- Section_02/assignment_02.py | 44 +++---------------------- Section_02/assignment_03.py | 36 ++++++++++---------- Section_02/assignment_04.py | 54 ++++++++++++++++++++++++------ Section_02/assignment_05.py | 66 +++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 74 deletions(-) create mode 100644 Section_02/assignment_05.py diff --git a/Section_02/assignment_01.py b/Section_02/assignment_01.py index 07bf2c7..fa1f33a 100644 --- a/Section_02/assignment_01.py +++ b/Section_02/assignment_01.py @@ -1,13 +1,12 @@ # Assignment 1: """ -Print Bill's salary from the my_list object shown below. - -my_list = [{'Tom': 20000, 'Bill': 12000}, ['car', 'laptop', 'TV']] + We would like to get the remainder of 15 divided by 4. + The calculation below does not seem to give us this result. + How would you change the code to meet the requirement? """ -# your code below: @@ -42,5 +41,11 @@ -# Solution -# print(my_list[0].get('Bill')) + + + +# Solution: + +# remainder = 15 % 4 +# print(remainder) + diff --git a/Section_02/assignment_02.py b/Section_02/assignment_02.py index 26e017b..a5636d1 100644 --- a/Section_02/assignment_02.py +++ b/Section_02/assignment_02.py @@ -1,44 +1,13 @@ # Assignment 2: """ -Using some of the collection data types we learned about -in the course so such as a list and dictionary, create a -data structure that best represents the following scenario: - -Tom has a salary of 20000 and is 22 years old. He owns a few items such as -a jacket, a car, and TV. Mike is another person who makes 24000 and is 27 years old -who owns a bike, a laptop and boat. -""" - -# your code below: - - - - - - - - - - - - - - - - - - - - - - - - - - +Use of the below format() method is incorrect for what we are trying to do. +We actually have 10 small, 12 large, and 12 medium boxes. +Write code to correct this: +print("We have {2} small boxes, {2} large boxes, {2} medium boxes".format(10,12,12)) +""" @@ -52,7 +21,4 @@ -# Solution -# my_list = [{'Tom': {'salary': 20000, 'age': 22, 'owns': ['jacket', 'car', 'TV']}}, -# {'Mike': {'salary': 24000, 'age': 27, 'owns': ['bike', 'laptop', 'boat']}}] diff --git a/Section_02/assignment_03.py b/Section_02/assignment_03.py index aee6b05..5d312a7 100644 --- a/Section_02/assignment_03.py +++ b/Section_02/assignment_03.py @@ -1,20 +1,26 @@ # Assignment 3: """ -There is a list shown below titled original_list. + Given 2 variables chars and word, write code to move + the data contained in the variable word in the exact middle of + the characters contained in the variable chars and save this + in a new variable called result and print it. -Using only what you've learned so far in the course, -write code to create a new list that contains the tuple sorted. + NOTE: chars variable will contain only 4 characters -IMPORTANT: you must do this programmatically! Don't just - hard code a new list with the values rearranged. -""" - -original_list = ['cup', 'cereal', 'milk', (8, 4, 3)] + Example: + --------------- + chars = "<<>>" + word = "hello" + result - should contain the following string: <> -# your code below: +""" +chars = "[[]]" +word = "Cool" +# Expected Result Printed: [[Cool]] +# Your code below: @@ -47,15 +53,7 @@ +# Solution Below: +# print(chars[:2] + word + chars[2:]) -# Solution -# num1 = original_list[3][0] -# num2 = original_list[3][1] -# num3 = original_list[3][2] -# new_list = [num1, num2, num3] -# new_list.sort() -# new_tuple = (new_list[0], new_list[1], new_list[2]) -# new_list = [original_list[0], original_list[1], original_list[2], new_tuple] -# -# print(new_list) \ No newline at end of file diff --git a/Section_02/assignment_04.py b/Section_02/assignment_04.py index 534a746..addb148 100644 --- a/Section_02/assignment_04.py +++ b/Section_02/assignment_04.py @@ -1,16 +1,51 @@ # Assignment 4: """ -In the list shown below, replace the letter m with the letter x -and replace the word TV with the word television. Then print my_list. + Given 2 variables word1 and word2, write code to + print the concatenation of the 2 words omitting the + first_folder letter of the string saved in word1 and the second_folder + letter of the string saved in word2. + + Example: + --------------- + word1 = "Vehicle" + word2 = "Robot" + result - ehicleRbot + """ -my_list = [(1, 2), (3, 4), (['c', 'd', 'a', 'm'], [3, 9, 4, 12], 4), 'TV', 42] +word1 = "Computer" +word2 = "Truck" + +# Expected Result Printed: omputerTuck + +# Your code below: + + + + + + + + + + + + + + + + + + + + + + + + -my_list[2][0][3] = 'x' -my_list[3] = 'Television' -print(my_list) @@ -21,9 +56,8 @@ +# Solution Below: +# result = word1[1:] + word2[0:1] + word2[2:] +# print(result) -# Solution: -# my_list[2][0][3] = 'x' -# my_list[3] = 'Television' -# print(my_list) \ No newline at end of file diff --git a/Section_02/assignment_05.py b/Section_02/assignment_05.py new file mode 100644 index 0000000..d672da4 --- /dev/null +++ b/Section_02/assignment_05.py @@ -0,0 +1,66 @@ +# Assignment 5: +""" + Given 2 variables chars and word, write code to move + the data contained in the variable word in the exact middle of + the characters contained in the variable chars and save this + in a new variable called result and print it. + + NOTE: chars variable can contain any even number of characters. + the len() function can be used to figure out the length of a string + + Example: + --------------- + chars = "<[<||>]>" + word = "mirror" + result - should contain the following string: <[<|mirror|>]> + +""" + +chars = "<<[]]]" # this could be a very long string with an even length. +word = "Cool" + +# Expected Result Printed: <<[Cool]]] + + +# Your code below: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# Solution Below: +# size = len(chars) +# idx = int(size/2) # dividing results in a float datatype. +# print(chars[:idx] + word + chars[idx:]) + + From efc0ce74aec55838e7530e1d1e422127c397f71a Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 18:53:15 -0500 Subject: [PATCH 02/10] Add files via upload --- Section_02/assignment_01.py | 13 ++++----- Section_02/assignment_02.py | 55 +++++++++++++++++++++++++++++++++---- Section_02/assignment_03.py | 45 ++++++++++++++++++------------ Section_02/assignment_04.py | 28 +++++++------------ 4 files changed, 94 insertions(+), 47 deletions(-) diff --git a/Section_02/assignment_01.py b/Section_02/assignment_01.py index fa1f33a..742cfa9 100644 --- a/Section_02/assignment_01.py +++ b/Section_02/assignment_01.py @@ -1,13 +1,13 @@ # Assignment 1: """ - We would like to get the remainder of 15 divided by 4. - The calculation below does not seem to give us this result. - How would you change the code to meet the requirement? +Print Bill's salary from the my_list object shown below. -""" +my_list = [{'Tom': 20000, 'Bill': 12000}, ['car', 'laptop', 'TV']] +""" +# your code below: @@ -44,8 +44,7 @@ -# Solution: -# remainder = 15 % 4 -# print(remainder) +# Solution +# print(my_list[0].get('Bill')) diff --git a/Section_02/assignment_02.py b/Section_02/assignment_02.py index a5636d1..da7812a 100644 --- a/Section_02/assignment_02.py +++ b/Section_02/assignment_02.py @@ -1,13 +1,55 @@ # Assignment 2: """ -Use of the below format() method is incorrect for what we are trying to do. -We actually have 10 small, 12 large, and 12 medium boxes. -Write code to correct this: +Using some of the collection data types we learned about +in the course so such as a list and dictionary, create a +data structure that best represents the following scenario: + +Tom has a salary of 20000 and is 22 years old. He owns a few items such as +a jacket, a car, and TV. Mike is another person who makes 24000 and is 27 years old +who owns a bike, a laptop and boat. +""" + +# your code below: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -print("We have {2} small boxes, {2} large boxes, {2} medium boxes".format(10,12,12)) -""" @@ -21,4 +63,7 @@ +# Solution +# my_list = [{'Tom': {'salary': 20000, 'age': 22, 'owns': ['jacket', 'car', 'TV']}}, +# {'Mike': {'salary': 24000, 'age': 27, 'owns': ['bike', 'laptop', 'boat']}}] diff --git a/Section_02/assignment_03.py b/Section_02/assignment_03.py index 5d312a7..5e91adb 100644 --- a/Section_02/assignment_03.py +++ b/Section_02/assignment_03.py @@ -1,26 +1,29 @@ # Assignment 3: """ - Given 2 variables chars and word, write code to move - the data contained in the variable word in the exact middle of - the characters contained in the variable chars and save this - in a new variable called result and print it. +There is a list shown below titled original_list. - NOTE: chars variable will contain only 4 characters - - Example: - --------------- - chars = "<<>>" - word = "hello" - result - should contain the following string: <> +Using only what you've learned so far in the course, +write code to create a new list that contains the tuple sorted. +IMPORTANT: you must do this programmatically! Don't just + hard code a new list with the values rearranged. """ -chars = "[[]]" -word = "Cool" +original_list = ['cup', 'cereal', 'milk', (8, 4, 3)] + +# your code below: + + + + + + + + + + -# Expected Result Printed: [[Cool]] -# Your code below: @@ -53,7 +56,15 @@ -# Solution Below: -# print(chars[:2] + word + chars[2:]) +# Solution +# num1 = original_list[3][0] +# num2 = original_list[3][1] +# num3 = original_list[3][2] +# new_list = [num1, num2, num3] +# new_list.sort() +# new_tuple = (new_list[0], new_list[1], new_list[2]) +# new_list = [original_list[0], original_list[1], original_list[2], new_tuple] +# +# print(new_list) \ No newline at end of file diff --git a/Section_02/assignment_04.py b/Section_02/assignment_04.py index addb148..c3e2a50 100644 --- a/Section_02/assignment_04.py +++ b/Section_02/assignment_04.py @@ -1,30 +1,21 @@ # Assignment 4: """ - Given 2 variables word1 and word2, write code to - print the concatenation of the 2 words omitting the - first_folder letter of the string saved in word1 and the second_folder - letter of the string saved in word2. - - Example: - --------------- - word1 = "Vehicle" - word2 = "Robot" - result - ehicleRbot - +In the list shown below, replace the letter m with the letter x +and replace the word TV with the word television. Then print my_list. """ -word1 = "Computer" -word2 = "Truck" +my_list = [(1, 2), (3, 4), (['c', 'd', 'a', 'm'], [3, 9, 4, 12], 4), 'TV', 42] + -# Expected Result Printed: omputerTuck +# Your Code Below: -# Your code below: +print(my_list) @@ -56,8 +47,9 @@ -# Solution Below: -# result = word1[1:] + word2[0:1] + word2[2:] -# print(result) +# Solution: +# my_list[2][0][3] = 'x' +# my_list[3] = 'Television' +# print(my_list) \ No newline at end of file From 73b799a6800169b537cbcf703c7919038d4faf65 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 18:53:56 -0500 Subject: [PATCH 03/10] Delete assignment_05.py --- Section_02/assignment_05.py | 66 ------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 Section_02/assignment_05.py diff --git a/Section_02/assignment_05.py b/Section_02/assignment_05.py deleted file mode 100644 index d672da4..0000000 --- a/Section_02/assignment_05.py +++ /dev/null @@ -1,66 +0,0 @@ -# Assignment 5: -""" - Given 2 variables chars and word, write code to move - the data contained in the variable word in the exact middle of - the characters contained in the variable chars and save this - in a new variable called result and print it. - - NOTE: chars variable can contain any even number of characters. - the len() function can be used to figure out the length of a string - - Example: - --------------- - chars = "<[<||>]>" - word = "mirror" - result - should contain the following string: <[<|mirror|>]> - -""" - -chars = "<<[]]]" # this could be a very long string with an even length. -word = "Cool" - -# Expected Result Printed: <<[Cool]]] - - -# Your code below: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Solution Below: -# size = len(chars) -# idx = int(size/2) # dividing results in a float datatype. -# print(chars[:idx] + word + chars[idx:]) - - From 521c603c33b11b5b79e7bd02446e4b15efde7733 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 18:55:07 -0500 Subject: [PATCH 04/10] Add files via upload --- Section_01/assignment_01.py | 3 +++ Section_01/assignment_02.py | 12 ++++++++++++ Section_01/assignment_03.py | 4 ++++ Section_01/assignment_04.py | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/Section_01/assignment_01.py b/Section_01/assignment_01.py index 96bb182..fa1f33a 100644 --- a/Section_01/assignment_01.py +++ b/Section_01/assignment_01.py @@ -37,6 +37,9 @@ + + + diff --git a/Section_01/assignment_02.py b/Section_01/assignment_02.py index 3dc49a2..a5636d1 100644 --- a/Section_01/assignment_02.py +++ b/Section_01/assignment_02.py @@ -10,3 +10,15 @@ """ + + + + + + + + + + + + diff --git a/Section_01/assignment_03.py b/Section_01/assignment_03.py index 637873b..5d312a7 100644 --- a/Section_01/assignment_03.py +++ b/Section_01/assignment_03.py @@ -44,6 +44,10 @@ + + + + diff --git a/Section_01/assignment_04.py b/Section_01/assignment_04.py index 956262e..addb148 100644 --- a/Section_01/assignment_04.py +++ b/Section_01/assignment_04.py @@ -47,6 +47,10 @@ + + + + From 947df546acb6ba13305deb189d0547b05009b093 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 18:56:40 -0500 Subject: [PATCH 05/10] Add files via upload --- Section_03/assignment_01.py | 8 +++++--- Section_03/assignment_02.py | 14 +++++++++++--- Section_03/assignment_03.py | 17 ++++++++++++++--- Section_03/assignment_04.py | 10 +++++++--- Section_03/assignment_05.py | 17 +++++++++++------ 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Section_03/assignment_01.py b/Section_03/assignment_01.py index 8b6564a..3688656 100644 --- a/Section_03/assignment_01.py +++ b/Section_03/assignment_01.py @@ -7,10 +7,12 @@ # your code below: -def merge_lists(list_a, list_b): - return list_a + list_b -print(merge_lists([1,2,3,4], ['a','b','c'])) + + + + + diff --git a/Section_03/assignment_02.py b/Section_03/assignment_02.py index 67d82d0..3e74ab6 100644 --- a/Section_03/assignment_02.py +++ b/Section_03/assignment_02.py @@ -7,10 +7,18 @@ Make sure to test the function. """ # Your Code Below: -def separate(str): - return list(str) -print(separate("hello there")) + + + + + + + + + + + diff --git a/Section_03/assignment_03.py b/Section_03/assignment_03.py index ee5b370..0d9731f 100644 --- a/Section_03/assignment_03.py +++ b/Section_03/assignment_03.py @@ -10,10 +10,21 @@ """ # Your Code Below: -def multi_merge(list_a, str): - return list_a + str.split() + list(str) -print(multi_merge([1,2,3,4], "Hello My name is imtiaz")) + + + + + + + + + + + + + + diff --git a/Section_03/assignment_04.py b/Section_03/assignment_04.py index 530a070..a33876f 100644 --- a/Section_03/assignment_04.py +++ b/Section_03/assignment_04.py @@ -14,11 +14,15 @@ # Your code below: -def last_list(*args): - return args[-1] -print(last_list([1,2,3,4,5], ['a', 'b', 'c'], ['mike', 'john'])) + + + + + + + diff --git a/Section_03/assignment_05.py b/Section_03/assignment_05.py index 8f5663e..425df0b 100644 --- a/Section_03/assignment_05.py +++ b/Section_03/assignment_05.py @@ -15,13 +15,18 @@ # Your Code Below: -def key_list_items(key, **kwargs): - value_list = kwargs[key] - return value_list[-2] -result = key_list_items("things", things=['book', 'tv', 'shoes'], people=['pete', 'mike', 'jan', 'tom'], - ages=[20, 30, 40]) -print(result) + + + + + + + + + + + From 6a54a604a5e9e906363881dda117fa2784e9ab8b Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 18:57:15 -0500 Subject: [PATCH 06/10] Add files via upload --- Section_04/Assignment_09.py | 44 ++++++++++++++++++++++--------------- Section_04/assignment_01.py | 13 +++++++++-- Section_04/assignment_02.py | 11 ++++++++-- Section_04/assignment_03.py | 11 +++++----- Section_04/assignment_04.py | 10 ++++----- Section_04/assignment_05.py | 11 ++-------- Section_04/assignment_06.py | 20 +++++------------ 7 files changed, 63 insertions(+), 57 deletions(-) diff --git a/Section_04/Assignment_09.py b/Section_04/Assignment_09.py index 488f886..d3150d2 100644 --- a/Section_04/Assignment_09.py +++ b/Section_04/Assignment_09.py @@ -36,31 +36,15 @@ } -# Your Code below: +# Your Code Below: # -------------------------------------- -line_list = [] -for line in fr: - columns = line.split("|") - lookup_val = columns[0] - # if lookup_val not in d.keys(): - if(d.get(lookup_val) is None): # Can't find email in dict - next_number = int(max(d.values())) + 1 - d[lookup_val] = str(next_number) - columns[0] = str(next_number) - line_list.append("|".join(columns)) - else: # we were able to find email in dictionary - columns[0] = d.get(lookup_val) - line_list.append("|".join(columns)) -fr = line_list - - -# don't change the below: +# don't change the lines below: # -------------------------------------- print("Value of fr: ") print(fr) @@ -82,6 +66,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + # Solution: # # line_list = [] diff --git a/Section_04/assignment_01.py b/Section_04/assignment_01.py index abf45ed..f3313a1 100644 --- a/Section_04/assignment_01.py +++ b/Section_04/assignment_01.py @@ -12,8 +12,17 @@ """ -def twelver(a, b): - return (a == 12 or b == 12 or a+b == 12) +# Your Code Below: + + + + + + + + + + diff --git a/Section_04/assignment_02.py b/Section_04/assignment_02.py index 10f2464..d0dc7b5 100644 --- a/Section_04/assignment_02.py +++ b/Section_04/assignment_02.py @@ -17,8 +17,15 @@ pay_extra(True, 6) -> true """ -def pay_extra(working, hour): - return (working and (hour < 8 or hour > 20)) +# Your Code Below: + + + + + + + + diff --git a/Section_04/assignment_03.py b/Section_04/assignment_03.py index e194fe7..6d4d390 100644 --- a/Section_04/assignment_03.py +++ b/Section_04/assignment_03.py @@ -11,14 +11,13 @@ sequence([]) → False """ -def sequence(num_list): - for i in range(len(num_list)-2): - if num_list[i] == 1 and num_list[i+1] == 2 and num_list[i+2] == 3: - return True +# Your Code Below: + + + + - return False -print(sequence([])) diff --git a/Section_04/assignment_04.py b/Section_04/assignment_04.py index ba5d7ce..b5940c4 100644 --- a/Section_04/assignment_04.py +++ b/Section_04/assignment_04.py @@ -9,16 +9,14 @@ """ -def grow_string(str): +# Your Code Below: + + + - result = "" - for i in range(len(str)): - result = result + str[:i + 1] - return result -print(grow_string("Imtiaz")) diff --git a/Section_04/assignment_05.py b/Section_04/assignment_05.py index 5a6f98d..3b61d70 100644 --- a/Section_04/assignment_05.py +++ b/Section_04/assignment_05.py @@ -13,19 +13,12 @@ """ -def first3(numbers): +# Your Code Below: + - end = len(numbers) - if end > 4: - end = 4 - for i in range(end): # loop over index 0,1,2,3 - if numbers[i] == 6: - return True - # if we get here, the loop is over and we didn't find a 6 - return False print(first3([1,2,6,3,0,0])) # true diff --git a/Section_04/assignment_06.py b/Section_04/assignment_06.py index 96b31e8..8219b61 100644 --- a/Section_04/assignment_06.py +++ b/Section_04/assignment_06.py @@ -16,21 +16,8 @@ """ -def last2(str): +# Your Code Below: - if len(str) <= 2: - return 0 - - # last 2 chars can also be extracted with str[-2:] - last2 = str[len(str) - 2:] - count = 0 - - for i in range(len(str) - 2): - sub = str[i : i+2] - if sub == last2: - count = count + 1 - - return count print(last2('hixxhi')) #→ 1 @@ -53,6 +40,11 @@ def last2(str): + + + + + From b27a3595a22642b54d19fe2634621cb74a17b18a Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 18:59:47 -0500 Subject: [PATCH 07/10] Rename Assignment_09.py to assignment_09.py --- Section_04/{Assignment_09.py => assignment_09.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Section_04/{Assignment_09.py => assignment_09.py} (100%) diff --git a/Section_04/Assignment_09.py b/Section_04/assignment_09.py similarity index 100% rename from Section_04/Assignment_09.py rename to Section_04/assignment_09.py From 48eda6bbbce16400551d360616b85fe9a93c93ac Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 19:00:07 -0500 Subject: [PATCH 08/10] Add files via upload --- Section_04/assignment_07.py | 15 +-------------- Section_04/assignment_08.py | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/Section_04/assignment_07.py b/Section_04/assignment_07.py index 07c878a..32484a0 100644 --- a/Section_04/assignment_07.py +++ b/Section_04/assignment_07.py @@ -12,20 +12,7 @@ """ -def string_match(a, b): - - # Figure out which string is shorter - shorter = min(len(a), len(b)) - - count = 0 - - for i in range(shorter - 1): - a_sub = a[i: i+2] # gives us substring of size 2 - b_sub = b[i: i+2] - if a_sub == b_sub: - count = count + 1 - - return count +#Your Code Below: diff --git a/Section_04/assignment_08.py b/Section_04/assignment_08.py index e8cbbf6..49ebe3d 100644 --- a/Section_04/assignment_08.py +++ b/Section_04/assignment_08.py @@ -14,24 +14,22 @@ """ -def sum78(nums): +#Your Code Below: + + + + + + + + + - sum = 0 - in_range = False - for i in range(len(nums)): - if nums[i] == 7: - in_range = True - if in_range == False: - # sum = sum + nums[i] - sum += nums[i] - if nums[i] == 8: - in_range = False - return sum print(sum78([1, 2, 2])) #→ 5 From 94d21cccf1ec4f3796379a8bf8cff24a33f6c220 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 19:00:57 -0500 Subject: [PATCH 09/10] Add files via upload --- Section_05/assignment_01.py | 126 +++++++++++++++++++++++++----------- 1 file changed, 89 insertions(+), 37 deletions(-) diff --git a/Section_05/assignment_01.py b/Section_05/assignment_01.py index 6f45f12..3e8762f 100644 --- a/Section_05/assignment_01.py +++ b/Section_05/assignment_01.py @@ -12,60 +12,112 @@ dog, fish and bird and make them eat and move. """ +# Your Code Below: -class Animal: - def __init__(self): - print("Animal Constructed") - def move(self): - print("Animal Moving...") - def eat(self): - print("Animal Eating...") -class Bird(Animal): - def __init__(self, bird_age, bird_name): - Animal.__init__(self) - self.age = bird_age - self.name = bird_name - def move(self): - print("Bird flying...") -class Fish(Animal): - def __init__(self, bird_age, bird_name): - Animal.__init__(self) - self.age = bird_age - self.name = bird_name - def move(self): - print("Fish Swimming...") -class Dog(Animal): - def __init__(self, bird_age, bird_name): - Animal.__init__(self) - self.age = bird_age - self.name = bird_name - def move(self): - print("Dog Running ...") -mydog = Dog(3, "wolfy") -mydog.move() -mydog.eat() -mydog = Fish(1, "nemo") -mydog.move() -mydog.eat() -mydog = Bird(3, "jojo") -mydog.move() -mydog.eat() \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# Solution: +# class Animal: +# def __init__(self): +# print("Animal Constructed") +# +# def move(self): +# print("Animal Moving...") +# +# def eat(self): +# print("Animal Eating...") +# +# +# +# class Bird(Animal): +# +# def __init__(self, bird_age, bird_name): +# Animal.__init__(self) +# self.age = bird_age +# self.name = bird_name +# +# def move(self): +# print("Bird flying...") +# +# +# +# class Fish(Animal): +# +# def __init__(self, bird_age, bird_name): +# Animal.__init__(self) +# self.age = bird_age +# self.name = bird_name +# +# def move(self): +# print("Fish Swimming...") +# +# +# class Dog(Animal): +# +# def __init__(self, bird_age, bird_name): +# Animal.__init__(self) +# self.age = bird_age +# self.name = bird_name +# +# def move(self): +# print("Dog Running ...") +# +# mydog = Dog(3, "wolfy") +# mydog.move() +# mydog.eat() +# +# mydog = Fish(1, "nemo") +# mydog.move() +# mydog.eat() +# +# mydog = Bird(3, "jojo") +# mydog.move() +# mydog.eat() \ No newline at end of file From 3daf38778dad8576e7312b4570cdc92ba6a13a9b Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmad Date: Tue, 23 Feb 2021 19:01:18 -0500 Subject: [PATCH 10/10] Add files via upload --- Section_06/assignment_01.py | 73 ++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/Section_06/assignment_01.py b/Section_06/assignment_01.py index c6ab6dd..10583e5 100644 --- a/Section_06/assignment_01.py +++ b/Section_06/assignment_01.py @@ -12,21 +12,68 @@ # Expected Output: # {"there": n, "Michael": n, "running": n} -words_and_counts = {} +# Your Code Below: -for word in words_to_aggregate: - count = 0 - for path, folder_names, file_names in os.walk(directory_containing_files): - for file_name in file_names: - file = os.path.join(path, file_name) - with open(file, "r") as a_file: - for line in a_file: - if re.search(word, line): - word_list = re.findall(word, line) - count += len(word_list) - words_and_counts[word] = count -print(words_and_counts) \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#Solution: +# words_and_counts = {} +# +# for word in words_to_aggregate: +# count = 0 +# for path, folder_names, file_names in os.walk(directory_containing_files): +# for file_name in file_names: +# file = os.path.join(path, file_name) +# with open(file, "r") as a_file: +# for line in a_file: +# if re.search(word, line): +# word_list = re.findall(word, line) +# count += len(word_list) +# +# words_and_counts[word] = count +# +# +# +# print(words_and_counts) \ No newline at end of file