diff --git a/homeworks/05_Boryana_Stefanova/avg_brightness.py b/homeworks/05_Boryana_Stefanova/avg_brightness.py new file mode 100644 index 0000000..05533f6 --- /dev/null +++ b/homeworks/05_Boryana_Stefanova/avg_brightness.py @@ -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) diff --git a/homeworks/05_Boryana_Stefanova/replace.py b/homeworks/05_Boryana_Stefanova/replace.py new file mode 100644 index 0000000..9b5dab5 --- /dev/null +++ b/homeworks/05_Boryana_Stefanova/replace.py @@ -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) diff --git a/homeworks/05_Boryana_Stefanova/steps_task.py b/homeworks/05_Boryana_Stefanova/steps_task.py new file mode 100644 index 0000000..7ce17e4 --- /dev/null +++ b/homeworks/05_Boryana_Stefanova/steps_task.py @@ -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))