Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 1_beginner/chapter5/practice/alternating.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
"""
Alternating
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@code-for-tomorrow/python who submitted this practice problem? I'm wondering because I noticed there's no solution for it...

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
is 1, -1, 2, -2, 3, -3, 4, -4, 5. (Note, DO NOT include the last negative
number).
Do this with a for loop
"""

# Write code here.
Expand Down
24 changes: 14 additions & 10 deletions 2_intermediate/chapter10/practice/img_avg.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
33 changes: 20 additions & 13 deletions 2_intermediate/chapter10/solutions/img_avg.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -37,9 +41,12 @@

# write code to create newimg here
def solution1():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Citrus716 could you change this to not be a function since the students haven't learned them yet?

"""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]
Expand Down