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
2 changes: 1 addition & 1 deletion 1_beginner/chapter3/solutions/temperature.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Temperature
# Temperature
# Write a program that converts Celsius to Fahrenheit.
# It should ask the user for the temperature in
# degrees Celsius and then print the temperature in degrees Fahrenheit.
Expand Down
4 changes: 1 addition & 3 deletions 1_beginner/chapter5/practice/add_all_the_way.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
# write code here




#Try using the other loop and do the same p[roblem again
# Try using the other loop and do the same p[roblem again
4 changes: 2 additions & 2 deletions 1_beginner/chapter5/practice/alternating.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

"""

#Write code here.
# Write code here.

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


#Now try it with a while loop
# Now try it with a while loop
8 changes: 4 additions & 4 deletions 1_beginner/chapter5/practice/fibonnaci.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
''' CHALLENGE PROBLEM!! NOT FOR THE FAINT OF HEART!
""" CHALLENGE PROBLEM!! NOT FOR THE FAINT OF HEART!

The Fibonacci numbers, discovered by Leonardo di Fibonacci,
is a sequence of numbers that often shows up in mathematics and,
Expand All @@ -12,9 +12,9 @@

The challenge is to use a for loop (not recursion, if you know what that is),
to find the 100th Fibonnaci number.
'''
"""

#write code here
# write code here


#Can you do it with a while loop?
# Can you do it with a while loop?
4 changes: 2 additions & 2 deletions 1_beginner/chapter5/practice/prime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"""

#write code here
# write code here

numer = int(input("Enter number here: "))

Expand All @@ -25,4 +25,4 @@

"""

#write code here
# write code here
2 changes: 1 addition & 1 deletion 1_beginner/chapter5/practice/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
Also, try adding up 1 -1/3 + 1/5 - 1/7 + 1/9 - 1/11 ... 10 million times. then
multiply this result by 4. What number is this close to?

"""
"""
4 changes: 2 additions & 2 deletions 2_intermediate/chapter10/practice/img_avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
plt.imshow(img)
plt.show()

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

plt.imshow(newimg)
plt.show()

plt.imshow(transpose)
plt.show()
plt.show()
82 changes: 40 additions & 42 deletions 2_intermediate/chapter10/solutions/img_avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,48 @@
transpose = numpy.transpose(img)


#write code to create newimg here
# 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.
"""Iterating over the image here. i is a variable from 0 to the width of the image.

Choose a reason for hiding this comment

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

E501: line too long (83 > 79 characters)

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]
y_n = [0]

if(i == 0):
x_n.append(1)
elif(i == len(img)-1):
x_n.append(-1)
else:
x_n.append(1)
x_n.append(-1)

if(j == 0):
y_n.append(1)
elif(j == len(img[0])-1):
y_n.append(-1)
else:
y_n.append(1)
y_n.append(-1)

r_avg = -1*img[i][j][0]
g_avg = -1*img[i][j][1]
b_avg = -1*img[i][j][2]
c = -1

for x in x_n:
for y in y_n:
r_avg += img[i+x][j+y][0]
g_avg += img[i+x][j+y][1]
b_avg += img[i+x][j+y][2]
c+=1
r_avg = r_avg/c
g_avg = g_avg/c
b_avg = b_avg/c

newimg[i][j] = [r_avg, g_avg, b_avg]


for i in range(len(img)):
for j in range(len(img[0])):
x_n = [0]
y_n = [0]

if i == 0:
x_n.append(1)
elif i == len(img) - 1:
x_n.append(-1)
else:
x_n.append(1)
x_n.append(-1)

if j == 0:
y_n.append(1)
elif j == len(img[0]) - 1:
y_n.append(-1)
else:
y_n.append(1)
y_n.append(-1)

r_avg = -1 * img[i][j][0]
g_avg = -1 * img[i][j][1]
b_avg = -1 * img[i][j][2]
c = -1

for x in x_n:
for y in y_n:
r_avg += img[i + x][j + y][0]
g_avg += img[i + x][j + y][1]
b_avg += img[i + x][j + y][2]
c += 1
r_avg = r_avg / c
g_avg = g_avg / c
b_avg = b_avg / c

newimg[i][j] = [r_avg, g_avg, b_avg]


solution1()
Expand All @@ -87,4 +85,4 @@ def solution1():
plt.show()

plt.imshow(transpose)
plt.show()
plt.show()
15 changes: 15 additions & 0 deletions 2_intermediate/chapter11/practice/remove_duplicates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Write a function called remove_duplicates
# The sole parameter of the function should be a list
# The function should look through a list,
# Find all duplicate elements, and remove them
# Sort the resulting list
# YOU MAY NOT USE THE set() function IN PYTHON.
# Hint: To sort a list, use sorted(list)
# Another hint: Use dict.removekeys(list)
# To take the elements from a list,
# and convert them to keys in a dictionary

# Example: array = [1,1,2,5,4,6,12,3,4,6]
# Result should print [1,2,3,4,5,6,12]

# Write code here
32 changes: 32 additions & 0 deletions 2_intermediate/chapter11/solutions/remove_duplicates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Write a function called remove_duplicates
# The sole parameter of the function should be a list
# The function should look through a list,
# Find all duplicate elements, and remove them
# Sort the resulting list
# YOU MAY NOT USE THE set() function IN PYTHON.
# Hint: To sort a list, use sorted(list)
# Another hint: Use dict.fromkeys(list)
# To take the elements from a list,
# and convert them to keys in a dictionary

# Example: array = [1,1,2,5,4,6,12,3,4,6]
# Result should print [1,2,3,4,5,6,12]

# Write code here

list1 = [1, 1, 2, 5, 4, 6, 12, 3, 4, 6] # Define your list


# Define your Function
def remove_duplicates(array):
my_list = list(dict.fromkeys(array))
# Converts the list into a dictionary.
# Fromkeys(array) turns each item into a key
# There cannot be multiple keys,
# So all the duplicate keys are removed
# Convert the keys back into a list
return sorted(my_list)
# Returns the sorted list of keys that are not duplicate.


print(remove_duplicates(list1)) # Call the function