Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
20e09c6
Changed img_avg.py template
Citrus716 Aug 6, 2020
7eec75c
Update img_avg.py solution
Citrus716 Aug 6, 2020
365dbd3
Made the characters per line less in alternating
Citrus716 Aug 7, 2020
2d2872b
Added my solution to alternating.py.
Citrus716 Aug 7, 2020
ca5a514
Fix code style issues with Black
lint-action Aug 7, 2020
992b468
Fix style alternating.py
phrdang Aug 7, 2020
3ae0314
Fix style and clarify instructions for img_avg.py
phrdang Aug 7, 2020
5a5daa6
Fix code style issues with Black
lint-action Aug 7, 2020
ef8914b
Add push events to workflows
phrdang Aug 7, 2020
4f8b1f4
Ignore flake8 rule E203 (black is correct)
phrdang Aug 7, 2020
bfe10d8
Remove on push event
phrdang Aug 7, 2020
c10fa84
Added how to install libraries
Citrus716 Aug 11, 2020
56415f6
Fix code style issues with Black
lint-action Aug 11, 2020
62a2930
Added instruction to installing libraries in solution
Citrus716 Aug 11, 2020
eabe3ac
Swapped i and j descriptions and added more.
Citrus716 Aug 15, 2020
ae9464f
Merge branch 'master' into kc_req_changes
Citrus716 Nov 14, 2020
f0541b3
Merge branch 'master' into kc_req_changes
Citrus716 Nov 14, 2020
1826aec
Fix code style issues with Black
lint-action Nov 14, 2020
504d8de
Merge branch 'master' into kc_req_changes
Citrus716 Nov 21, 2020
0d7e11c
Fix code style issues with Black
lint-action Nov 21, 2020
5bc4134
Delete this file because it no longer exists
BenVN123 May 28, 2021
11b478a
Delete this because the file no longer exists
BenVN123 May 28, 2021
2ce575b
Delete this because the file no longer exists
BenVN123 May 28, 2021
9694652
Delete this because the file no longer exists
BenVN123 May 28, 2021
53a79ba
Merge pull request #126 from code4tomorrow/BenVN123-patch-14
BenVN123 May 28, 2021
ff95a82
Merge pull request #125 from code4tomorrow/BenVN123-patch-9
BenVN123 May 28, 2021
fa15ff8
Merge pull request #123 from code4tomorrow/BenVN123-patch-2
BenVN123 May 28, 2021
0dce285
Merge pull request #124 from code4tomorrow/BenVN123-patch-4
BenVN123 May 28, 2021
e71aaae
Merge branch 'master' into kc_req_changes
BenVN123 May 28, 2021
2901452
Fix styling error
BenVN123 May 28, 2021
07b3c99
Merge branch 'master' into kc_req_changes
chrehall68 May 29, 2021
fb69a9a
Merge branch 'master' into kc_req_changes
BenVN123 May 29, 2021
f589aa2
Merge branch 'master' into kc_req_changes
BenVN123 Jun 11, 2021
862f2ca
Merge branch 'master' into kc_req_changes
BenVN123 Jun 26, 2021
c6d5573
Merge branch 'master' into kc_req_changes
BenVN123 Jul 7, 2021
d036912
Merge branch 'master' into kc_req_changes
BenVN123 Aug 7, 2021
d353069
Merge branch 'master' into kc_req_changes
BenVN123 Aug 9, 2021
a3c604a
Fix it so that it works
chrehall68 Aug 9, 2021
e65f509
Fix code style issues with Black
lint-action Aug 9, 2021
81c198b
Fix comment so that it's w/i line length limit
chrehall68 Aug 9, 2021
948c7c0
Merge branch 'kc_req_changes' of https://github.com/code4tomorrow/pyt…
chrehall68 Aug 9, 2021
233c2d5
Add comments, fix small bug
chrehall68 Aug 9, 2021
5ef9329
Update workflows to match what it is in main branch
chrehall68 Aug 9, 2021
ca6b173
Update names.py to match what it is in main branch
chrehall68 Aug 9, 2021
88c72e7
Fix comment
BenVN123 Aug 9, 2021
a91d7f6
Edit comment
BenVN123 Aug 9, 2021
f4c6905
Update alternating.py
BenVN123 Aug 9, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/python-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
black_args: "--line-length 79 --exclude='1_beginner/chapter1/examples/error.py'" # same max line length as flake8
flake8_args: "--max-line-length=88 --ignore=E203,W503 --exclude=1_beginner/chapter1/examples/error.py" # prevent conflicts with black
auto_fix: true # auto commit style fixes


17 changes: 6 additions & 11 deletions 1_beginner/chapter5/practice/alternating.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
"""
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
is 1, -1, 2, -2, 3, -3, 4, -4, 5. (Note, DO NOT include the last negative
number).

Do this with a for loop
Ask the user for a positive integer. Then 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 and then with a while loop.
"""

# Write code here.

number = int(input("Enter Number Here: "))

# Write code here

# Now try it with a while loop
27 changes: 27 additions & 0 deletions 1_beginner/chapter5/solutions/alternating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Alternating
Ask the user for a positive integer. Then 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 and then with a while loop.
"""

# for loop solution
number = int(input("Enter number here: "))
for num in range(1, number + 1):
if num == number:
print(num)
else:
print(num)
print(-num)


# while loop solution
number = int(input("Enter number here: "))
current_num = 1
while current_num < number:
print(current_num)
print(-current_num)
current_num += 1
print(current_num)
83 changes: 58 additions & 25 deletions 2_intermediate/chapter10/practice/img_avg.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,83 @@
"""
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 RGB (red, green, blue) value
which determines the color of the pixel.
Here is the challenge problem for nested loops:
Images are often represented as 3D lists.
The outer list is the entire image.
The 1st level inner list is a row of pixels.
The 2nd level inner list is the RGB values for that pixel.
RGB (red, green, blue) values determine 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
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 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.
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.
calculate the average of the red values, blue values, and green values.
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]
original one would be [15, 75, 35] (since the average of 20 and 10 is 15,
the average of 30 and 120 is 75, and the average of 40 and 30 is 35).

EXAMPLE: An image with 9 pixels may look like:
[
[
[31, 41, 42], [51, 1, 101], [24, 141, 33]
],

[
[50, 21, 28], [31, 49, 201], [90, 54, 33]
],

[
[12, 81, 3], [22, 8, 91], [101, 141, 132]
]
]

HINT: Don't forget that a pixel may have varying amount of neighboring
pixels. A pixel at the edge, for example, has 3 neighboring pixels while
a pixel at the center of the image has 8 neighboring pixels (one on each
of its 4 sides, and then one at each of its 4 corners).
"""

# Import libraries needed to run the program
# Before importing the libraries, you must have them installed.
# This problem requires the following libraries:
# pillow, requests, numpy, and matplotlib
# If you don't already have them installed, open your command prompt or terminal
# and please do
# this: pip install -U (library) (any other libraries, each separated by a space)
# ex: pip install -U numpy matplotlib requests pillow
# Note: on some windows machines, you may need to
# do: py -m pip install -U (library) (any other libraries, each separated by a space)

from PIL import Image
import requests
import numpy
import matplotlib.pyplot as plt

url = "https://images.dog.ceo/breeds/waterdog-spanish/20180723_185544.jpg"
img = numpy.array(Image.open(requests.get(url, stream=True).raw)).tolist()
newimg = img
transpose = numpy.transpose(img)
# Code that grabs the image from the internet and makes it into an array
IMAGE_URL = (
"https://images.dog.ceo/breeds/waterdog-spanish/20180723_185544.jpg"
)
img = numpy.array(
Image.open(requests.get(IMAGE_URL, stream=True).raw)
).tolist()

# create newimg as an empty list so that we'll know if something went wrong
# ie. if we try to display it and the function didn't run, we'd get an
# invalid shape error
newimg = [[[] for column in row] for row in img]

# Code that displays the original image
print("now displaying the original image")
plt.imshow(img)
plt.show()

# write code to create newimg here
# Write code to create newimg here

# Code that displays the new image at the end
print("now displaying the new image")
plt.imshow(newimg)
plt.show()

plt.imshow(transpose)
plt.show()
Loading