From 397c89c3778909460d361038f4813e16eff8e8a2 Mon Sep 17 00:00:00 2001 From: Alexandra Stancheva <66909315+allks12@users.noreply.github.com> Date: Mon, 18 Oct 2021 19:44:05 +0300 Subject: [PATCH 1/4] Add files via upload Homework for circles. --- homeworks/04_Alexandra_Stancheva/alexandra.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 homeworks/04_Alexandra_Stancheva/alexandra.py diff --git a/homeworks/04_Alexandra_Stancheva/alexandra.py b/homeworks/04_Alexandra_Stancheva/alexandra.py new file mode 100644 index 0000000..8629b04 --- /dev/null +++ b/homeworks/04_Alexandra_Stancheva/alexandra.py @@ -0,0 +1,36 @@ +from math import sqrt + + +def calc_distance(center1, center2): + diff_x = center1[0] - center2[0] + diff_y = center1[1] - center2[1] + return sqrt(diff_x**2 + diff_y**2) + + +def check_cicles(center1, radius1, center2, radius2): + if center1 == center2 and radius1 == radius2: + return "MATCHING" + + distance = calc_distance(center1, center2) + + if distance < radius1 - radius2 or distance < radius2 - radius1: + return "CONTAINING" + + if distance < radius1 + radius2: + return "INTERSECTING" + + if distance > radius1 + radius2: + return "NO_COMMON" + + if distance == radius1 + radius2: + return "TOUCHING" + + +if __name__ == "__main__": + test_center1 = (2, 5) + test_radius1 = 4 + + test_center2 = (2, 5) + test_radius2 = 4 + + print(check_cicles(test_center1, test_radius1, test_center2, test_radius2)) From 5ce3e92b6788ba1069c667965012231a20cc34a3 Mon Sep 17 00:00:00 2001 From: Alexandra Stancheva <66909315+allks12@users.noreply.github.com> Date: Mon, 18 Oct 2021 19:48:40 +0300 Subject: [PATCH 2/4] Add files via upload --- .../01_check_circles.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 homeworks/04_Alexandra_Stancheva/01_check_circles.py diff --git a/homeworks/04_Alexandra_Stancheva/01_check_circles.py b/homeworks/04_Alexandra_Stancheva/01_check_circles.py new file mode 100644 index 0000000..8629b04 --- /dev/null +++ b/homeworks/04_Alexandra_Stancheva/01_check_circles.py @@ -0,0 +1,36 @@ +from math import sqrt + + +def calc_distance(center1, center2): + diff_x = center1[0] - center2[0] + diff_y = center1[1] - center2[1] + return sqrt(diff_x**2 + diff_y**2) + + +def check_cicles(center1, radius1, center2, radius2): + if center1 == center2 and radius1 == radius2: + return "MATCHING" + + distance = calc_distance(center1, center2) + + if distance < radius1 - radius2 or distance < radius2 - radius1: + return "CONTAINING" + + if distance < radius1 + radius2: + return "INTERSECTING" + + if distance > radius1 + radius2: + return "NO_COMMON" + + if distance == radius1 + radius2: + return "TOUCHING" + + +if __name__ == "__main__": + test_center1 = (2, 5) + test_radius1 = 4 + + test_center2 = (2, 5) + test_radius2 = 4 + + print(check_cicles(test_center1, test_radius1, test_center2, test_radius2)) From 4a5b412eea072fd3e6724e1080414e0c756f2b75 Mon Sep 17 00:00:00 2001 From: Alexandra Stancheva <66909315+allks12@users.noreply.github.com> Date: Mon, 18 Oct 2021 19:49:27 +0300 Subject: [PATCH 3/4] Delete alexandra.py --- homeworks/04_Alexandra_Stancheva/alexandra.py | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 homeworks/04_Alexandra_Stancheva/alexandra.py diff --git a/homeworks/04_Alexandra_Stancheva/alexandra.py b/homeworks/04_Alexandra_Stancheva/alexandra.py deleted file mode 100644 index 8629b04..0000000 --- a/homeworks/04_Alexandra_Stancheva/alexandra.py +++ /dev/null @@ -1,36 +0,0 @@ -from math import sqrt - - -def calc_distance(center1, center2): - diff_x = center1[0] - center2[0] - diff_y = center1[1] - center2[1] - return sqrt(diff_x**2 + diff_y**2) - - -def check_cicles(center1, radius1, center2, radius2): - if center1 == center2 and radius1 == radius2: - return "MATCHING" - - distance = calc_distance(center1, center2) - - if distance < radius1 - radius2 or distance < radius2 - radius1: - return "CONTAINING" - - if distance < radius1 + radius2: - return "INTERSECTING" - - if distance > radius1 + radius2: - return "NO_COMMON" - - if distance == radius1 + radius2: - return "TOUCHING" - - -if __name__ == "__main__": - test_center1 = (2, 5) - test_radius1 = 4 - - test_center2 = (2, 5) - test_radius2 = 4 - - print(check_cicles(test_center1, test_radius1, test_center2, test_radius2)) From 64c2bd100da8e7caf8a3f0d0c6a08f2d2328fc1b Mon Sep 17 00:00:00 2001 From: Alexandra Stancheva <66909315+allks12@users.noreply.github.com> Date: Wed, 12 Jan 2022 22:03:20 +0200 Subject: [PATCH 4/4] Add files via upload --- .../alexandra_04_homework_2/task_1.py | 77 +++++++++++++++++++ .../alexandra_04_homework_2/task_2.py | 19 +++++ .../alexandra_04_homework_2/task_3.py | 21 +++++ 3 files changed, 117 insertions(+) create mode 100644 homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_1.py create mode 100644 homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_2.py create mode 100644 homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_3.py diff --git a/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_1.py b/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_1.py new file mode 100644 index 0000000..8807cf6 --- /dev/null +++ b/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_1.py @@ -0,0 +1,77 @@ +class Picture: + def __init__(self, colums, lines, matrix): + self.colums = colums + self.lines = lines + self.matrix = matrix + + def check_matrix(self): + for i in range(0, self.colums): + for y in range(0, self.lines): + if self.matrix[i][y] < 0 or self.matrix[i][y] > 255: + return False + return True + +def check_element(matrix, x, y, colums, lines, sum, flag): + if matrix[x][y] == 0: + return [[0], [0], 0] + + random_point = matrix[x][y] + sum[0] = sum[0] + matrix[x][y] + flag[0] = flag[0] + 1 + matrix[x][y] = 0 + + if x < (colums - 1): + check_element(matrix, x + 1, y, colums, lines, sum, flag) + + if x < (colums - 1) and y < (lines - 1): + check_element(matrix, x + 1, y + 1, colums, lines, sum, flag) + + if y < (lines - 1): + check_element(matrix, x, y + 1, colums, lines, sum, flag)[0] + + + return [sum, flag, random_point] + +def avg_brightness(picture): + working_matrix = picture.matrix + avgs = [] + avgs_index = 0 + + + for i in range(0, picture.colums): + for y in range(0, picture.lines): + sum = [0] + flag = [0] + result = [0, 0] + result = check_element(working_matrix, i, y, picture.colums, picture.lines, sum, flag) + sum = result[0] + flag = result[1] + + if sum[0] > 0: + print(f'Random point in area {avgs_index + 1} : {result[2]} \n') + avgs.insert(avgs_index, sum[0] / flag[0]) + avgs_index = avgs_index + 1 + + avgs.sort(reverse = True) + + return avgs + +matrix = [[2, 2, 0, 5, 3], + [0, 0, 0, 3, 5], + [0, 0, 0, 0, 0], + [0, 1, 2, 3, 0], + [0, 0, 0, 0, 0]] + +p1 = Picture(5, 5, matrix) + +if p1.check_matrix() is False: + print("Invalid matrix numbers!") +else: + average_p1 = avg_brightness(p1) + + print("\nAverage brightness of areas:\n") + + print(average_p1) + + for i in range (0, len(average_p1)): + print(f'\nArea {i + 1} : {average_p1[i]}\n') \ No newline at end of file diff --git a/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_2.py b/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_2.py new file mode 100644 index 0000000..42cbc65 --- /dev/null +++ b/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_2.py @@ -0,0 +1,19 @@ +def num_ways(N): + first_num = 0 + second_num = 1 + ways = 0 + + for i in range(1, (N + 1)): + ways = first_num + second_num + first_num = second_num + second_num = ways + + return ways + +stairs1 = 5 +ways_for_stairs1 = num_ways(stairs1) +print(f'{stairs1} steps could be walked by {ways_for_stairs1} ways.\n') + +stairs2 = 15 +ways_for_stairs2 = num_ways(stairs2) +print(f'{stairs2} steps could be walked by {ways_for_stairs2} ways.\n') \ No newline at end of file diff --git a/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_3.py b/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_3.py new file mode 100644 index 0000000..c27c320 --- /dev/null +++ b/homeworks/04_Alexandra_Stancheva/alexandra_04_homework_2/task_3.py @@ -0,0 +1,21 @@ + +def replace(current_list, find, replacement): + for i in range(0, len(current_list)): + if isinstance(current_list[i], list): + replace(current_list[i], find, replacement) + + if type(current_list[i]) is tuple: + new_list = list(current_list[i]) + replace(new_list, find, replacement) + current_list[i] = tuple(new_list) + + if current_list[i] == find: + current_list[i] = replacement + + + +my_list = [ 'a', 1, [ ['a', 'b'], 1], ([1, 3, 'a'], 'b')] + +replace(my_list, 'a', 'c') + +print(my_list)