-
-
Notifications
You must be signed in to change notification settings - Fork 14
Kc req changes #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Kc req changes #43
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 7eec75c
Update img_avg.py solution
Citrus716 365dbd3
Made the characters per line less in alternating
Citrus716 2d2872b
Added my solution to alternating.py.
Citrus716 ca5a514
Fix code style issues with Black
lint-action 992b468
Fix style alternating.py
phrdang 3ae0314
Fix style and clarify instructions for img_avg.py
phrdang 5a5daa6
Fix code style issues with Black
lint-action ef8914b
Add push events to workflows
phrdang 4f8b1f4
Ignore flake8 rule E203 (black is correct)
phrdang bfe10d8
Remove on push event
phrdang c10fa84
Added how to install libraries
Citrus716 56415f6
Fix code style issues with Black
lint-action 62a2930
Added instruction to installing libraries in solution
Citrus716 eabe3ac
Swapped i and j descriptions and added more.
Citrus716 ae9464f
Merge branch 'master' into kc_req_changes
Citrus716 f0541b3
Merge branch 'master' into kc_req_changes
Citrus716 1826aec
Fix code style issues with Black
lint-action 504d8de
Merge branch 'master' into kc_req_changes
Citrus716 0d7e11c
Fix code style issues with Black
lint-action 5bc4134
Delete this file because it no longer exists
BenVN123 11b478a
Delete this because the file no longer exists
BenVN123 2ce575b
Delete this because the file no longer exists
BenVN123 9694652
Delete this because the file no longer exists
BenVN123 53a79ba
Merge pull request #126 from code4tomorrow/BenVN123-patch-14
BenVN123 ff95a82
Merge pull request #125 from code4tomorrow/BenVN123-patch-9
BenVN123 fa15ff8
Merge pull request #123 from code4tomorrow/BenVN123-patch-2
BenVN123 0dce285
Merge pull request #124 from code4tomorrow/BenVN123-patch-4
BenVN123 e71aaae
Merge branch 'master' into kc_req_changes
BenVN123 2901452
Fix styling error
BenVN123 07b3c99
Merge branch 'master' into kc_req_changes
chrehall68 fb69a9a
Merge branch 'master' into kc_req_changes
BenVN123 f589aa2
Merge branch 'master' into kc_req_changes
BenVN123 862f2ca
Merge branch 'master' into kc_req_changes
BenVN123 c6d5573
Merge branch 'master' into kc_req_changes
BenVN123 d036912
Merge branch 'master' into kc_req_changes
BenVN123 d353069
Merge branch 'master' into kc_req_changes
BenVN123 a3c604a
Fix it so that it works
chrehall68 e65f509
Fix code style issues with Black
lint-action 81c198b
Fix comment so that it's w/i line length limit
chrehall68 948c7c0
Merge branch 'kc_req_changes' of https://github.com/code4tomorrow/pyt…
chrehall68 233c2d5
Add comments, fix small bug
chrehall68 5ef9329
Update workflows to match what it is in main branch
chrehall68 ca6b173
Update names.py to match what it is in main branch
chrehall68 88c72e7
Fix comment
BenVN123 a91d7f6
Edit comment
BenVN123 f4c6905
Update alternating.py
BenVN123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.