Skip to content

Commit 6b2c1c2

Browse files
committed
Merge branch 'Citrus716-patch-2-1' into kehao-ch10problems
I'm merging to fix style issues detected by Lintly (flake8)
2 parents ac594d8 + db2fa9b commit 6b2c1c2

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

1_beginner/chapter5/practice/alternating.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
"""
1+
"""
2+
Alternating
23
34
Ask the user for an integer. The print the numbers from 1 to that number,
45
but alternating in sign. For example, if the input was 5, what would be printed
56
is 1, -1, 2, -2, 3, -3, 4, -4, 5. (Note, DO NOT include the last negative
67
number).
78
89
Do this with a for loop
9-
1010
"""
1111

1212
# Write code here.

2_intermediate/chapter10/practice/img_avg.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
""" Here is the challenge problem for 2d loops>
2-
Images are often represented as 3d arrays,
1+
"""
2+
Image Average
3+
4+
Here is the challenge problem for 2D loops:
5+
Images are often represented as 3D arrays,
36
where the rows and columns are the pixels in the image,
4-
and each pixel has an r, g, and b value.
7+
and each pixel has an RGB (red, green, blue) value
8+
which determines the color of the pixel.
59
610
The interesting thing is that we can iterate over images.
711
The challenge is, given an image, create a program that
812
will return a different image where each pixel is the average
913
of the pixels surrounding it in the original image.
1014
11-
The neighbors of an image are all the pixels that surroun it,
12-
1 on each side, and 4 on the diagonals, for 8 in total.
13-
Each pixel doesn't necessarily have 8 neighbors, though (think about why)
15+
The neighbors of an image are all the pixels that surround it,
16+
1 on each side, and 4 on the diagonals, for 8 in total. Each
17+
pixel doesn't necessarily have 8 neighbors, though (think about why).
1418
1519
The code to grab an image from the internet and make it
1620
into an array is given to you. The code also displays the new image
1721
you create in the end.
1822
19-
NOTE: The image is 3 dimensional because each pixel has rgb values.
23+
NOTE: The image is 3 dimensional because each pixel has RGB values.
2024
To find the average value of all of a pixels neighbors, you must
2125
change the average of the red value to the red value, blue to blue, etc.
22-
For example, if the neighbors of a pixel with value [1,2,3]
23-
were [20,30,40] and [10,120,30], the new pixel that would replace the original one would be
24-
[15,75,35]
26+
For example, if the neighbors of a pixel with value [1, 2, 3]
27+
were [20, 30, 40] and [10, 120, 30], the new pixel that would replace the
28+
original one would be [15, 75, 35]
2529
"""
2630

2731
from PIL import Image

2_intermediate/chapter10/solutions/img_avg.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
""" Here is the challenge problem for 2d loops>
2-
Images are often represented as 3d arrays,
1+
"""
2+
Image Average
3+
4+
Here is the challenge problem for 2D loops:
5+
Images are often represented as 3D arrays,
36
where the rows and columns are the pixels in the image,
4-
and each pixel has an r, g, and b value.
7+
and each pixel has an RGB (red, green, blue) value
8+
which determines the color of the pixel.
59
610
The interesting thing is that we can iterate over images.
711
The challenge is, given an image, create a program that
812
will return a different image where each pixel is the average
913
of the pixels surrounding it in the original image.
1014
11-
The neighbors of an image are all the pixels that surroun it,
12-
1 on each side, and 4 on the diagonals, for 8 in total.
13-
Each pixel doesn't necessarily have 8 neighbors, though (think about why)
15+
The neighbors of an image are all the pixels that surround it,
16+
1 on each side, and 4 on the diagonals, for 8 in total. Each
17+
pixel doesn't necessarily have 8 neighbors, though (think about why).
1418
1519
The code to grab an image from the internet and make it
1620
into an array is given to you. The code also displays the new image
1721
you create in the end.
1822
19-
NOTE: The image is 3 dimensional because each pixel has rgb values.
23+
NOTE: The image is 3 dimensional because each pixel has RGB values.
2024
To find the average value of all of a pixels neighbors, you must
2125
change the average of the red value to the red value, blue to blue, etc.
22-
For example, if the neighbors of a pixel with value [1,2,3]
23-
were [20,30,40] and [10,120,30], the new pixel that would replace the original one would be
24-
[15,75,35]
26+
For example, if the neighbors of a pixel with value [1, 2, 3]
27+
were [20, 30, 40] and [10, 120, 30], the new pixel that would replace the
28+
original one would be [15, 75, 35]
2529
"""
2630

2731
from PIL import Image
@@ -37,9 +41,12 @@
3741

3842
# write code to create newimg here
3943
def solution1():
40-
"""Iterating over the image here. i is a variable from 0 to the width of the image.
41-
j is a variable that ranges from 0 to the height of the image. i is associated with
42-
values"""
44+
"""
45+
Iterating over the image here. i is a variable from
46+
0 to the width of the image.
47+
j is a variable that ranges from 0 to the height of the image.
48+
i is associated with values
49+
"""
4350
for i in range(len(img)):
4451
for j in range(len(img[0])):
4552
x_n = [0]

0 commit comments

Comments
 (0)