From 0e662ccb27556351d7361d8718a3bb712664847c Mon Sep 17 00:00:00 2001 From: Citrus716 <60357364+Citrus716@users.noreply.github.com> Date: Sun, 2 Aug 2020 22:17:46 -0400 Subject: [PATCH 01/11] Added odd_sum and smooth_max Added odd_sum and smooth_max that I created --- 2_intermediate/chapter10/practice/odd_sum.py | 11 +++++++++++ 2_intermediate/chapter10/practice/smooth_max.py | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 2_intermediate/chapter10/practice/odd_sum.py create mode 100644 2_intermediate/chapter10/practice/smooth_max.py diff --git a/2_intermediate/chapter10/practice/odd_sum.py b/2_intermediate/chapter10/practice/odd_sum.py new file mode 100644 index 00000000..175c4755 --- /dev/null +++ b/2_intermediate/chapter10/practice/odd_sum.py @@ -0,0 +1,11 @@ +# Odd Sum +# Given a 2D list, find the sum of all elements at odd indexes for all +# the lists at odd indexes. Print this sum times the sum of all +# first element of all the 1D lists in the 2D list. +# +# Ex:[[1,2,3,6],[2,41,2,1]]should have print 42 after the program runs. +# +# Write the code below. + +two_d_list = [[1,2,3,5,2],[2,3,1,4],[2,3,1,2,21],[21,3,1,41]] +#two_d_list should print 51 after the program runs. diff --git a/2_intermediate/chapter10/practice/smooth_max.py b/2_intermediate/chapter10/practice/smooth_max.py new file mode 100644 index 00000000..cdeb3467 --- /dev/null +++ b/2_intermediate/chapter10/practice/smooth_max.py @@ -0,0 +1,10 @@ +# Given a 2D list, let's call a element "smooth" if index of the +# element in its 1D list plus the element is even. For example, +# given the 2D list [[0,4][2,6]], the 1st element of each of the +# 1D list is considered "smooth" because 0 + 0 is 0 and 0 + 2 is 2 +# (both are even numbers). Find the maximum "smooth" element and +# print it. Using the example [[0,4][2,6]] again, the maximum +# "smooth" element is 2 because 2 is bigger than 0. + +two_d_list = [[425,214,412,123],[312,214,123,343]] + From d00e8533f6ff9afb36d471146631a6e1ad758618 Mon Sep 17 00:00:00 2001 From: Citrus716 <60357364+Citrus716@users.noreply.github.com> Date: Sun, 2 Aug 2020 22:18:29 -0400 Subject: [PATCH 02/11] Added odd_sum and smooth_max solutions Added odd_sum and smooth_max solutions that I created --- 2_intermediate/chapter10/solutions/odd_sum.py | 11 +++++++++++ 2_intermediate/chapter10/solutions/smooth_max.py | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 2_intermediate/chapter10/solutions/odd_sum.py create mode 100644 2_intermediate/chapter10/solutions/smooth_max.py diff --git a/2_intermediate/chapter10/solutions/odd_sum.py b/2_intermediate/chapter10/solutions/odd_sum.py new file mode 100644 index 00000000..175c4755 --- /dev/null +++ b/2_intermediate/chapter10/solutions/odd_sum.py @@ -0,0 +1,11 @@ +# Odd Sum +# Given a 2D list, find the sum of all elements at odd indexes for all +# the lists at odd indexes. Print this sum times the sum of all +# first element of all the 1D lists in the 2D list. +# +# Ex:[[1,2,3,6],[2,41,2,1]]should have print 42 after the program runs. +# +# Write the code below. + +two_d_list = [[1,2,3,5,2],[2,3,1,4],[2,3,1,2,21],[21,3,1,41]] +#two_d_list should print 51 after the program runs. diff --git a/2_intermediate/chapter10/solutions/smooth_max.py b/2_intermediate/chapter10/solutions/smooth_max.py new file mode 100644 index 00000000..cdeb3467 --- /dev/null +++ b/2_intermediate/chapter10/solutions/smooth_max.py @@ -0,0 +1,10 @@ +# Given a 2D list, let's call a element "smooth" if index of the +# element in its 1D list plus the element is even. For example, +# given the 2D list [[0,4][2,6]], the 1st element of each of the +# 1D list is considered "smooth" because 0 + 0 is 0 and 0 + 2 is 2 +# (both are even numbers). Find the maximum "smooth" element and +# print it. Using the example [[0,4][2,6]] again, the maximum +# "smooth" element is 2 because 2 is bigger than 0. + +two_d_list = [[425,214,412,123],[312,214,123,343]] + From fd2ed28f074226acc5425d6d7cf53776805e1a5e Mon Sep 17 00:00:00 2001 From: Citrus716 <60357364+Citrus716@users.noreply.github.com> Date: Sun, 2 Aug 2020 22:19:57 -0400 Subject: [PATCH 03/11] Wrong file uploaded --- 2_intermediate/chapter10/solutions/odd_sum.py | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 2_intermediate/chapter10/solutions/odd_sum.py diff --git a/2_intermediate/chapter10/solutions/odd_sum.py b/2_intermediate/chapter10/solutions/odd_sum.py deleted file mode 100644 index 175c4755..00000000 --- a/2_intermediate/chapter10/solutions/odd_sum.py +++ /dev/null @@ -1,11 +0,0 @@ -# Odd Sum -# Given a 2D list, find the sum of all elements at odd indexes for all -# the lists at odd indexes. Print this sum times the sum of all -# first element of all the 1D lists in the 2D list. -# -# Ex:[[1,2,3,6],[2,41,2,1]]should have print 42 after the program runs. -# -# Write the code below. - -two_d_list = [[1,2,3,5,2],[2,3,1,4],[2,3,1,2,21],[21,3,1,41]] -#two_d_list should print 51 after the program runs. From 985cb0046f7232306fe9667dd598f80de0061288 Mon Sep 17 00:00:00 2001 From: Citrus716 <60357364+Citrus716@users.noreply.github.com> Date: Sun, 2 Aug 2020 22:20:10 -0400 Subject: [PATCH 04/11] Wrong file uploaded 2 --- 2_intermediate/chapter10/solutions/smooth_max.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 2_intermediate/chapter10/solutions/smooth_max.py diff --git a/2_intermediate/chapter10/solutions/smooth_max.py b/2_intermediate/chapter10/solutions/smooth_max.py deleted file mode 100644 index cdeb3467..00000000 --- a/2_intermediate/chapter10/solutions/smooth_max.py +++ /dev/null @@ -1,10 +0,0 @@ -# Given a 2D list, let's call a element "smooth" if index of the -# element in its 1D list plus the element is even. For example, -# given the 2D list [[0,4][2,6]], the 1st element of each of the -# 1D list is considered "smooth" because 0 + 0 is 0 and 0 + 2 is 2 -# (both are even numbers). Find the maximum "smooth" element and -# print it. Using the example [[0,4][2,6]] again, the maximum -# "smooth" element is 2 because 2 is bigger than 0. - -two_d_list = [[425,214,412,123],[312,214,123,343]] - From 5bc453011425c9888882211b187b647239214f65 Mon Sep 17 00:00:00 2001 From: Citrus716 <60357364+Citrus716@users.noreply.github.com> Date: Sun, 2 Aug 2020 22:20:52 -0400 Subject: [PATCH 05/11] Added odd_sum and smooth_max solutions Added odd_sum and smooth_max solutions that I created --- 2_intermediate/chapter10/solutions/odd_sum.py | 25 +++++++++++++++++++ .../chapter10/solutions/smooth_max.py | 24 ++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 2_intermediate/chapter10/solutions/odd_sum.py create mode 100644 2_intermediate/chapter10/solutions/smooth_max.py diff --git a/2_intermediate/chapter10/solutions/odd_sum.py b/2_intermediate/chapter10/solutions/odd_sum.py new file mode 100644 index 00000000..2a94bb7c --- /dev/null +++ b/2_intermediate/chapter10/solutions/odd_sum.py @@ -0,0 +1,25 @@ +# Odd Sum +# Given a 2D list, find the sum of all elements at odd indexes for all +# the lists at odd indexes. Print this sum times the sum of all +# first element of all the 1D lists in the 2D list. +# +# Ex:[[1,2,3,6],[2,41,2,1]]should have print 42 after the program runs. +# +# Write the code below. + +two_d_list = [[1,2,3,5,2],[2,3,1,4],[2,3,1,2,21],[21,3,1,41]] +#two_d_list should print 51 after the program runs. + +odd_sum = 0 +for outer_idx in range(1,len(two_d_list),2): + for inner_idx in range(1, len(two_d_list[outer_idx]),2): + odd_sum += two_d_list[outer_idx][inner_idx] + +first_sum = 0 +for inner_list in range(len(two_d_list)): + first_sum += two_d_list[inner_list][0] + +print(odd_sum* first_sum ) + + + diff --git a/2_intermediate/chapter10/solutions/smooth_max.py b/2_intermediate/chapter10/solutions/smooth_max.py new file mode 100644 index 00000000..eafa1bd6 --- /dev/null +++ b/2_intermediate/chapter10/solutions/smooth_max.py @@ -0,0 +1,24 @@ +# Given a 2D list, let's call a element "smooth" if index of the +# element in its 1D list plus the element is even. For example, +# given the 2D list [[0,4][2,6]], the 1st element of each of the +# 1D list is considered "smooth" because 0 + 0 is 0 and 0 + 2 is 2 +# (both are even numbers). Find the maximum "smooth" element and +# print it. Using the example [[0,4][2,6]] again, the maximum +# "smooth" element is 2 because 2 is bigger than 0. + +two_d_list = [[425,214,412,123],[312,214,123,343]] +curr_max = None + +for outer_idx in range(len(two_d_list)): + for inner_idx in range(len(two_d_list[outer_idx])): + curr_elem = two_d_list[outer_idx][inner_idx] + to_check = curr_elem + inner_idx + if to_check % 2 == 0: + if curr_max == None or curr_elem > curr_max: + curr_max = curr_elem + +print(curr_max) + + + + From 11247b9e5934d3048bd133b205febc10214a04dd Mon Sep 17 00:00:00 2001 From: Lint Action Date: Mon, 3 Aug 2020 02:22:25 +0000 Subject: [PATCH 06/11] Fix code style issues with Black --- 2_intermediate/chapter10/practice/odd_sum.py | 4 ++-- 2_intermediate/chapter10/practice/smooth_max.py | 5 ++--- 2_intermediate/chapter10/solutions/odd_sum.py | 13 +++++-------- 2_intermediate/chapter10/solutions/smooth_max.py | 10 +++------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/2_intermediate/chapter10/practice/odd_sum.py b/2_intermediate/chapter10/practice/odd_sum.py index 175c4755..a07d215b 100644 --- a/2_intermediate/chapter10/practice/odd_sum.py +++ b/2_intermediate/chapter10/practice/odd_sum.py @@ -7,5 +7,5 @@ # # Write the code below. -two_d_list = [[1,2,3,5,2],[2,3,1,4],[2,3,1,2,21],[21,3,1,41]] -#two_d_list should print 51 after the program runs. +two_d_list = [[1, 2, 3, 5, 2], [2, 3, 1, 4], [2, 3, 1, 2, 21], [21, 3, 1, 41]] +# two_d_list should print 51 after the program runs. diff --git a/2_intermediate/chapter10/practice/smooth_max.py b/2_intermediate/chapter10/practice/smooth_max.py index cdeb3467..6530e8ae 100644 --- a/2_intermediate/chapter10/practice/smooth_max.py +++ b/2_intermediate/chapter10/practice/smooth_max.py @@ -3,8 +3,7 @@ # given the 2D list [[0,4][2,6]], the 1st element of each of the # 1D list is considered "smooth" because 0 + 0 is 0 and 0 + 2 is 2 # (both are even numbers). Find the maximum "smooth" element and -# print it. Using the example [[0,4][2,6]] again, the maximum +# print it. Using the example [[0,4][2,6]] again, the maximum # "smooth" element is 2 because 2 is bigger than 0. -two_d_list = [[425,214,412,123],[312,214,123,343]] - +two_d_list = [[425, 214, 412, 123], [312, 214, 123, 343]] diff --git a/2_intermediate/chapter10/solutions/odd_sum.py b/2_intermediate/chapter10/solutions/odd_sum.py index 2a94bb7c..eff7cc7e 100644 --- a/2_intermediate/chapter10/solutions/odd_sum.py +++ b/2_intermediate/chapter10/solutions/odd_sum.py @@ -7,19 +7,16 @@ # # Write the code below. -two_d_list = [[1,2,3,5,2],[2,3,1,4],[2,3,1,2,21],[21,3,1,41]] -#two_d_list should print 51 after the program runs. +two_d_list = [[1, 2, 3, 5, 2], [2, 3, 1, 4], [2, 3, 1, 2, 21], [21, 3, 1, 41]] +# two_d_list should print 51 after the program runs. odd_sum = 0 -for outer_idx in range(1,len(two_d_list),2): - for inner_idx in range(1, len(two_d_list[outer_idx]),2): +for outer_idx in range(1, len(two_d_list), 2): + for inner_idx in range(1, len(two_d_list[outer_idx]), 2): odd_sum += two_d_list[outer_idx][inner_idx] first_sum = 0 for inner_list in range(len(two_d_list)): first_sum += two_d_list[inner_list][0] -print(odd_sum* first_sum ) - - - +print(odd_sum * first_sum) diff --git a/2_intermediate/chapter10/solutions/smooth_max.py b/2_intermediate/chapter10/solutions/smooth_max.py index eafa1bd6..6bf27f94 100644 --- a/2_intermediate/chapter10/solutions/smooth_max.py +++ b/2_intermediate/chapter10/solutions/smooth_max.py @@ -3,22 +3,18 @@ # given the 2D list [[0,4][2,6]], the 1st element of each of the # 1D list is considered "smooth" because 0 + 0 is 0 and 0 + 2 is 2 # (both are even numbers). Find the maximum "smooth" element and -# print it. Using the example [[0,4][2,6]] again, the maximum +# print it. Using the example [[0,4][2,6]] again, the maximum # "smooth" element is 2 because 2 is bigger than 0. -two_d_list = [[425,214,412,123],[312,214,123,343]] +two_d_list = [[425, 214, 412, 123], [312, 214, 123, 343]] curr_max = None for outer_idx in range(len(two_d_list)): for inner_idx in range(len(two_d_list[outer_idx])): curr_elem = two_d_list[outer_idx][inner_idx] to_check = curr_elem + inner_idx - if to_check % 2 == 0: + if to_check % 2 == 0: if curr_max == None or curr_elem > curr_max: curr_max = curr_elem print(curr_max) - - - - From ac594d8e01dd9bcb9227c0decd67bc0dadd6f4d1 Mon Sep 17 00:00:00 2001 From: Citrus716 <60357364+Citrus716@users.noreply.github.com> Date: Sun, 2 Aug 2020 22:32:25 -0400 Subject: [PATCH 07/11] Update smooth_max.py --- 2_intermediate/chapter10/solutions/smooth_max.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2_intermediate/chapter10/solutions/smooth_max.py b/2_intermediate/chapter10/solutions/smooth_max.py index 6bf27f94..a61465f6 100644 --- a/2_intermediate/chapter10/solutions/smooth_max.py +++ b/2_intermediate/chapter10/solutions/smooth_max.py @@ -14,7 +14,7 @@ curr_elem = two_d_list[outer_idx][inner_idx] to_check = curr_elem + inner_idx if to_check % 2 == 0: - if curr_max == None or curr_elem > curr_max: + if curr_max is None or curr_elem > curr_max: curr_max = curr_elem print(curr_max) From b3d9a8e81e6a312310af5be638ef493846d596af Mon Sep 17 00:00:00 2001 From: Citrus716 <60357364+Citrus716@users.noreply.github.com> Date: Sun, 2 Aug 2020 23:43:06 -0400 Subject: [PATCH 08/11] Update img_avg.py --- 2_intermediate/chapter10/practice/img_avg.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/2_intermediate/chapter10/practice/img_avg.py b/2_intermediate/chapter10/practice/img_avg.py index 34d7c040..36cc4867 100644 --- a/2_intermediate/chapter10/practice/img_avg.py +++ b/2_intermediate/chapter10/practice/img_avg.py @@ -1,4 +1,4 @@ -""" Here is the challenge problem for 2d loops> +""" Here is the challenge problem for 2d loops: Images are often represented as 3d arrays, where the rows and columns are the pixels in the image, and each pixel has an r, g, and b value. @@ -8,9 +8,9 @@ will return a different image where each pixel is the average of the pixels surrounding it in the original image. -The neighbors of an image are all the pixels that surroun it, -1 on each side, and 4 on the diagonals, for 8 in total. -Each pixel doesn't necessarily have 8 neighbors, though (think about why) +The neighbors of an image are all the pixels that surround it, +1 on each side, and 4 on the diagonals, for 8 in total. Each +pixel doesn't necessarily have 8 neighbors, though (think about why) The code to grab an image from the internet and make it into an array is given to you. The code also displays the new image @@ -20,8 +20,8 @@ To find the average value of all of a pixels neighbors, you must change the average of the red value to the red value, blue to blue, etc. For example, if the neighbors of a pixel with value [1,2,3] -were [20,30,40] and [10,120,30], the new pixel that would replace the original one would be -[15,75,35] +were [20,30,40] and [10,120,30], the new pixel that would replace the +original one would be [15,75,35] """ from PIL import Image From da99482ea90d6d049a429e9d27dd01d21e967e44 Mon Sep 17 00:00:00 2001 From: Rebecca Dang Date: Tue, 4 Aug 2020 13:49:29 -0700 Subject: [PATCH 09/11] Fix style --- 2_intermediate/chapter10/practice/img_avg.py | 20 ++++++----- 2_intermediate/chapter10/solutions/img_avg.py | 33 +++++++++++-------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/2_intermediate/chapter10/practice/img_avg.py b/2_intermediate/chapter10/practice/img_avg.py index 36cc4867..dc9de796 100644 --- a/2_intermediate/chapter10/practice/img_avg.py +++ b/2_intermediate/chapter10/practice/img_avg.py @@ -1,7 +1,11 @@ -""" Here is the challenge problem for 2d loops: -Images are often represented as 3d arrays, +""" +Image Average + +Here is the challenge problem for 2D loops: +Images are often represented as 3D arrays, where the rows and columns are the pixels in the image, -and each pixel has an r, g, and b value. +and each pixel has an RGB (red, green, blue) value +which determines the color of the pixel. The interesting thing is that we can iterate over images. The challenge is, given an image, create a program that @@ -10,18 +14,18 @@ The neighbors of an image are all the pixels that surround it, 1 on each side, and 4 on the diagonals, for 8 in total. Each -pixel doesn't necessarily have 8 neighbors, though (think about why) +pixel doesn't necessarily have 8 neighbors, though (think about why). The code to grab an image from the internet and make it into an array is given to you. The code also displays the new image you create in the end. -NOTE: The image is 3 dimensional because each pixel has rgb values. +NOTE: The image is 3 dimensional because each pixel has RGB values. To find the average value of all of a pixels neighbors, you must change the average of the red value to the red value, blue to blue, etc. -For example, if the neighbors of a pixel with value [1,2,3] -were [20,30,40] and [10,120,30], the new pixel that would replace the -original one would be [15,75,35] +For example, if the neighbors of a pixel with value [1, 2, 3] +were [20, 30, 40] and [10, 120, 30], the new pixel that would replace the +original one would be [15, 75, 35] """ from PIL import Image diff --git a/2_intermediate/chapter10/solutions/img_avg.py b/2_intermediate/chapter10/solutions/img_avg.py index 2961ce16..815ab8ea 100644 --- a/2_intermediate/chapter10/solutions/img_avg.py +++ b/2_intermediate/chapter10/solutions/img_avg.py @@ -1,27 +1,31 @@ -""" Here is the challenge problem for 2d loops> -Images are often represented as 3d arrays, +""" +Image Average + +Here is the challenge problem for 2D loops: +Images are often represented as 3D arrays, where the rows and columns are the pixels in the image, -and each pixel has an r, g, and b value. +and each pixel has an RGB (red, green, blue) value +which determines the color of the pixel. The interesting thing is that we can iterate over images. The challenge is, given an image, create a program that will return a different image where each pixel is the average of the pixels surrounding it in the original image. -The neighbors of an image are all the pixels that surroun it, -1 on each side, and 4 on the diagonals, for 8 in total. -Each pixel doesn't necessarily have 8 neighbors, though (think about why) +The neighbors of an image are all the pixels that surround it, +1 on each side, and 4 on the diagonals, for 8 in total. Each +pixel doesn't necessarily have 8 neighbors, though (think about why). The code to grab an image from the internet and make it into an array is given to you. The code also displays the new image you create in the end. -NOTE: The image is 3 dimensional because each pixel has rgb values. +NOTE: The image is 3 dimensional because each pixel has RGB values. To find the average value of all of a pixels neighbors, you must change the average of the red value to the red value, blue to blue, etc. -For example, if the neighbors of a pixel with value [1,2,3] -were [20,30,40] and [10,120,30], the new pixel that would replace the original one would be -[15,75,35] +For example, if the neighbors of a pixel with value [1, 2, 3] +were [20, 30, 40] and [10, 120, 30], the new pixel that would replace the +original one would be [15, 75, 35] """ from PIL import Image @@ -37,9 +41,12 @@ # write code to create newimg here def solution1(): - """Iterating over the image here. i is a variable from 0 to the width of the image. - j is a variable that ranges from 0 to the height of the image. i is associated with - values""" + """ + Iterating over the image here. i is a variable from + 0 to the width of the image. + j is a variable that ranges from 0 to the height of the image. + i is associated with values + """ for i in range(len(img)): for j in range(len(img[0])): x_n = [0] From 4d9bbe1e6e1c7384b363a7c2d4a1ec758e484124 Mon Sep 17 00:00:00 2001 From: Rebecca Dang Date: Tue, 4 Aug 2020 13:56:43 -0700 Subject: [PATCH 10/11] Fix style for Alternating and Names exercises --- 1_beginner/chapter5/practice/alternating.py | 4 ++-- 1_beginner/chapter6/solutions/names.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/1_beginner/chapter5/practice/alternating.py b/1_beginner/chapter5/practice/alternating.py index 9ae5eb98..a57c1dde 100644 --- a/1_beginner/chapter5/practice/alternating.py +++ b/1_beginner/chapter5/practice/alternating.py @@ -1,4 +1,5 @@ -""" +""" +Alternating Ask the user for an integer. The print the numbers from 1 to that number, but alternating in sign. For example, if the input was 5, what would be printed @@ -6,7 +7,6 @@ number). Do this with a for loop - """ # Write code here. diff --git a/1_beginner/chapter6/solutions/names.py b/1_beginner/chapter6/solutions/names.py index ef98419a..751dddcf 100644 --- a/1_beginner/chapter6/solutions/names.py +++ b/1_beginner/chapter6/solutions/names.py @@ -14,7 +14,7 @@ # Some other possible answers: # group = people[0, 5, 2] or people[0, len(people), 2] -group = people[0 : len(people) : 2] +group = people[0:len(people):2] print(people) print(group) From db2fa9be0ec0b2869585dbf4f6455bf845ff1050 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Tue, 4 Aug 2020 20:57:14 +0000 Subject: [PATCH 11/11] Fix code style issues with Black --- 1_beginner/chapter6/solutions/names.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1_beginner/chapter6/solutions/names.py b/1_beginner/chapter6/solutions/names.py index 751dddcf..ef98419a 100644 --- a/1_beginner/chapter6/solutions/names.py +++ b/1_beginner/chapter6/solutions/names.py @@ -14,7 +14,7 @@ # Some other possible answers: # group = people[0, 5, 2] or people[0, len(people), 2] -group = people[0:len(people):2] +group = people[0 : len(people) : 2] print(people) print(group)