diff --git a/1_beginner/chapter5/practice/alternating.py b/1_beginner/chapter5/practice/alternating.py index a57c1dde..9ae5eb98 100644 --- a/1_beginner/chapter5/practice/alternating.py +++ b/1_beginner/chapter5/practice/alternating.py @@ -1,5 +1,4 @@ -""" -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 @@ -7,6 +6,7 @@ number). Do this with a for loop + """ # Write code here. diff --git a/2_intermediate/chapter10/practice/img_avg.py b/2_intermediate/chapter10/practice/img_avg.py index dc9de796..34d7c040 100644 --- a/2_intermediate/chapter10/practice/img_avg.py +++ b/2_intermediate/chapter10/practice/img_avg.py @@ -1,31 +1,27 @@ -""" -Image Average - -Here is the challenge problem for 2D loops: -Images are often represented as 3D arrays, +""" 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 RGB (red, green, blue) value -which determines the color of the pixel. +and each pixel has an r, g, and b value. 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 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 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 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/practice/odd_sum.py b/2_intermediate/chapter10/practice/odd_sum.py deleted file mode 100644 index a07d215b..00000000 --- a/2_intermediate/chapter10/practice/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. diff --git a/2_intermediate/chapter10/practice/smooth_max.py b/2_intermediate/chapter10/practice/smooth_max.py deleted file mode 100644 index 6530e8ae..00000000 --- a/2_intermediate/chapter10/practice/smooth_max.py +++ /dev/null @@ -1,9 +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]] diff --git a/2_intermediate/chapter10/solutions/img_avg.py b/2_intermediate/chapter10/solutions/img_avg.py index 815ab8ea..2961ce16 100644 --- a/2_intermediate/chapter10/solutions/img_avg.py +++ b/2_intermediate/chapter10/solutions/img_avg.py @@ -1,31 +1,27 @@ -""" -Image Average - -Here is the challenge problem for 2D loops: -Images are often represented as 3D arrays, +""" 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 RGB (red, green, blue) value -which determines the color of the pixel. +and each pixel has an r, g, and b value. 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 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 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 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 @@ -41,12 +37,9 @@ # 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] diff --git a/2_intermediate/chapter10/solutions/odd_sum.py b/2_intermediate/chapter10/solutions/odd_sum.py deleted file mode 100644 index eff7cc7e..00000000 --- a/2_intermediate/chapter10/solutions/odd_sum.py +++ /dev/null @@ -1,22 +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. - -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 deleted file mode 100644 index a61465f6..00000000 --- a/2_intermediate/chapter10/solutions/smooth_max.py +++ /dev/null @@ -1,20 +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]] -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 is None or curr_elem > curr_max: - curr_max = curr_elem - -print(curr_max)