Skip to content
Open
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
30 changes: 30 additions & 0 deletions homeworks/05_Boryana_Stefanova/avg_brightness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
matrix = [
[1, 2, 3, 4, 5, 6],
[0, 0, 0, 0, 0, 0],
[2, 0, 14, 180, 0, 205],
[0, 0, 85, 0, 184, 0],
[108, 0, 0, 0, 0, 255],
[68, 0, 174, 0, 17, 0]
]

def blow(matrix, _i, _j):
avg = []
for i in range(_i - 1, _i + 2):
for j in range(_j - 1, _j + 2):
if i < 0 or j < 0 or i >= len(matrix) or j >= len(matrix[i]):
continue
if matrix[i][j] != 0:
avg.append(matrix[i][j])
matrix[i][j] = 0
avg.extend(blow(matrix, i, j))
return avg

def avg_brightness(matrix):
for i in range(len(matrix)):
for j in range(len(matrix[i])):
if matrix[i][j] != 0:
avg = blow(matrix, i, j)
result = sum(avg) / len(avg)
print(f"({i}:{j}) = {result:.2f}")

avg_brightness(matrix)
16 changes: 16 additions & 0 deletions homeworks/05_Boryana_Stefanova/replace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def replace(list, find, change):

counter = 0
for i in list:
if type(i) != int:
if len(i) > 1:
replace(list[counter], find, change)

if list[counter] == find:
list[counter] = change
counter = counter + 1
return list

list = [ 'a', 1, [ ['a', 'b'], 1], ([1, 3, 'a'], 'b')]
res = replace(list, 'a', 'c')
print(res)
13 changes: 13 additions & 0 deletions homeworks/05_Boryana_Stefanova/steps_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def stepCounter(steps):

if steps < 0:
return 0

if steps == 0:
return 1

return (stepCounter(steps-1) +
stepCounter(steps-2))

steps = 3
print(stepCounter(steps))