From 60e850108a3c5468401fe7eaadab89f03186fe6c Mon Sep 17 00:00:00 2001 From: ermmmaks Date: Mon, 29 Sep 2025 21:06:31 +0300 Subject: [PATCH 1/6] Add bubble_sort --- src/bubble_sort.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bubble_sort.py diff --git a/src/bubble_sort.py b/src/bubble_sort.py new file mode 100644 index 0000000..345fe6d --- /dev/null +++ b/src/bubble_sort.py @@ -0,0 +1,24 @@ +def bubble_sort(arr): + n = len(arr) + + for i in range(n): + swapped = False + + for j in range(n - i - 1): + if arr[j] > arr[j + 1]: + temporary = arr[j] + arr[j] = arr[j + 1] + arr[j + 1] = temporary + swapped = True + if not swapped: + return arr + +len_arr = int(input("Введите длину массива: ")) +user_arr = [] + +for count in range(len_arr): + user_number = int(input(f"Число номер {count + 1}: ")) + user_arr.append(user_number) + +print("Сортировка выполнена!") +print(bubble_sort(user_arr) ) \ No newline at end of file From 637f89b1522db0ab46e8964ce336f570b9dc2465 Mon Sep 17 00:00:00 2001 From: ermmmaks Date: Thu, 9 Oct 2025 23:08:52 +0300 Subject: [PATCH 2/6] Edit lexicographical order check algoritm with formater and linker Ruff and follow PEP8 --- src/lexicographical_order_ruff_edited.py | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/lexicographical_order_ruff_edited.py diff --git a/src/lexicographical_order_ruff_edited.py b/src/lexicographical_order_ruff_edited.py new file mode 100644 index 0000000..406b26c --- /dev/null +++ b/src/lexicographical_order_ruff_edited.py @@ -0,0 +1,39 @@ +USER_STR1 = str(input("Введите первую строку: ")) +USER_STR2 = str(input("Введите вторую строку: ")) +ALPHABET = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[::-1] +MIN_LEN = min(len(USER_STR1), len(USER_STR2)) + +# 1) чем символ дальше от начала алфавита (z), тем он старше +# 2) чем меньше длина строки, тем она старше + + +def lexic_order(string1, string2): + for latin in string1 + string2: + if latin not in ALPHABET: + return "Используйте только латиницу!" + + for let in range(0, MIN_LEN): + let_s1 = string1[let] + let_s2 = string2[let] + + if (let_s1 != let_s2) or ( + let == MIN_LEN - 1 and let_s1 == let_s2 + ): # сравнение возможно, если: + # 1. всретились разные буквы + # 2. буквы одинаковые вплоть до последнего символа одной из строк + if (ALPHABET.index(let_s1) > ALPHABET.index(let_s2)) or ( + len(string1) < len(string2) + and (let_s1 == let_s2) + and let == MIN_LEN - 1 + ): + return "Первая строка старше, чем Вторая" + elif (ALPHABET.index(let_s2) > ALPHABET.index(let_s1)) or ( + len(string1) > len(string2) + and (let_s1 == let_s2) + and let == MIN_LEN - 1 + ): + return "Вторая строка старше, чем Первая" + return "Строки идентичны" + + +print(lexic_order(USER_STR1, USER_STR2)) From f80bbed6e81996cc4e85d2bda6fb155abd348022 Mon Sep 17 00:00:00 2001 From: ermmmaks Date: Thu, 9 Oct 2025 23:20:19 +0300 Subject: [PATCH 3/6] Add lexicographical order check algorithm with checking by formatter and linker Ruff and folow PEP8 --- src/lexicographical_order_ruff.py | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/lexicographical_order_ruff.py diff --git a/src/lexicographical_order_ruff.py b/src/lexicographical_order_ruff.py new file mode 100644 index 0000000..406b26c --- /dev/null +++ b/src/lexicographical_order_ruff.py @@ -0,0 +1,39 @@ +USER_STR1 = str(input("Введите первую строку: ")) +USER_STR2 = str(input("Введите вторую строку: ")) +ALPHABET = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[::-1] +MIN_LEN = min(len(USER_STR1), len(USER_STR2)) + +# 1) чем символ дальше от начала алфавита (z), тем он старше +# 2) чем меньше длина строки, тем она старше + + +def lexic_order(string1, string2): + for latin in string1 + string2: + if latin not in ALPHABET: + return "Используйте только латиницу!" + + for let in range(0, MIN_LEN): + let_s1 = string1[let] + let_s2 = string2[let] + + if (let_s1 != let_s2) or ( + let == MIN_LEN - 1 and let_s1 == let_s2 + ): # сравнение возможно, если: + # 1. всретились разные буквы + # 2. буквы одинаковые вплоть до последнего символа одной из строк + if (ALPHABET.index(let_s1) > ALPHABET.index(let_s2)) or ( + len(string1) < len(string2) + and (let_s1 == let_s2) + and let == MIN_LEN - 1 + ): + return "Первая строка старше, чем Вторая" + elif (ALPHABET.index(let_s2) > ALPHABET.index(let_s1)) or ( + len(string1) > len(string2) + and (let_s1 == let_s2) + and let == MIN_LEN - 1 + ): + return "Вторая строка старше, чем Первая" + return "Строки идентичны" + + +print(lexic_order(USER_STR1, USER_STR2)) From 5dbf9b41acf91fca598251c5620de750e7c39a7f Mon Sep 17 00:00:00 2001 From: ermmmaks Date: Tue, 14 Oct 2025 00:36:02 +0300 Subject: [PATCH 4/6] Add all solution to the question about queens --- src/complexity.md | 16 +++++++++++++ src/dictionary_queens.py | 36 +++++++++++++++++++++++++++++ src/queens_on_the_table_1.py | 24 ++++++++++++++++++++ src/queens_on_the_table_2.py | 34 ++++++++++++++++++++++++++++ src/queens_on_the_table_3.py | 44 ++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 src/complexity.md create mode 100644 src/dictionary_queens.py create mode 100644 src/queens_on_the_table_1.py create mode 100644 src/queens_on_the_table_2.py create mode 100644 src/queens_on_the_table_3.py diff --git a/src/complexity.md b/src/complexity.md new file mode 100644 index 0000000..f231f99 --- /dev/null +++ b/src/complexity.md @@ -0,0 +1,16 @@ +Для первого, переборного решения: +1. Цикл из функции is_valid_place "for first_place in range(n):" имеет сложность O(N) +2. В функции queen_placement "permutations" занимает O(N!) +3. В добавок далее строится массив queens со сложностью O(N) + + Итого: O(N * N! * N) ~ O(N^2 * N!) + +Для второго, рекурсивного решения: +1. В функции trees_from_rows вызывется цикл перебора всех колонок N раз => O(N) +2. Рекурсивный вызов со сменой строки занимает O(N - 1) (первую строку уже посчитали) + + Итого: O(N * (N - 1)) ~ O(N!) + +Для третьего, чуть более оптимального решения со словарем: + I. Если N <= 15, то сложность программы - O(c) + II. Если N >= 15, то сложность как и у второй программы - O(N!) \ No newline at end of file diff --git a/src/dictionary_queens.py b/src/dictionary_queens.py new file mode 100644 index 0000000..68f5fe0 --- /dev/null +++ b/src/dictionary_queens.py @@ -0,0 +1,36 @@ +variations = [] + +def queens_placement(side): + + def trees_from_rows(row, columns, main_diagonal, collateral_diagonal): + + if row == side: + return 1 + + count = 0 + + for column in range(side): + main = row - column + collateral = row + column + + if (column not in columns and + (main) not in main_diagonal and + (collateral) not in collateral_diagonal): + + columns.add(column) + main_diagonal.add(main) + collateral_diagonal.add(collateral) + + count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal) + + columns.remove(column) + main_diagonal.remove(main) + collateral_diagonal.remove(collateral) + + return count + + return trees_from_rows(0, set(), set(), set()) + +for i in range(16, 20): + variations.append(queens_placement(i)) + print(variations) diff --git a/src/queens_on_the_table_1.py b/src/queens_on_the_table_1.py new file mode 100644 index 0000000..408f6e3 --- /dev/null +++ b/src/queens_on_the_table_1.py @@ -0,0 +1,24 @@ +import itertools + +USER_SIDE = int(input("Write the lenght of the side of the field: ")) + + +def is_valid_place(positions, n): + for first_place in range(n): + for second_place in range(first_place + 1, n): + row1, column1 = positions[first_place] + row2, column2 = positions[second_place] + if abs(row1 - row2) == abs(column1 - column2): + return False + return True + + +def queen_placement(side): + count = 0 + for rows in itertools.permutations(range(side)): + queens = [(row, column) for row, column in enumerate(rows)] + if is_valid_place(queens, side): + count += 1 + return count + +print("Count of right placing: ", queen_placement(USER_SIDE)) \ No newline at end of file diff --git a/src/queens_on_the_table_2.py b/src/queens_on_the_table_2.py new file mode 100644 index 0000000..4319ec4 --- /dev/null +++ b/src/queens_on_the_table_2.py @@ -0,0 +1,34 @@ +def queens_placement(SIDE): + + def trees_from_rows(row, columns, main_diagonal, collateral_diagonal): + + if row == SIDE: + return 1 + + count = 0 + + for column in range(SIDE): + main = row - column + collateral = row + column + + if (column not in columns and + (main) not in main_diagonal and + (collateral) not in collateral_diagonal): + + columns.add(column) + main_diagonal.add(main) + collateral_diagonal.add(collateral) + + count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal) + + columns.remove(column) + main_diagonal.remove(main) + collateral_diagonal.remove(collateral) + + return count + + return trees_from_rows(0, set(), set(), set()) + +USER_SIDE = int(input("Write the value of the side of the field: ")) + +print("Count of right placing: ", queens_placement(USER_SIDE)) \ No newline at end of file diff --git a/src/queens_on_the_table_3.py b/src/queens_on_the_table_3.py new file mode 100644 index 0000000..489b524 --- /dev/null +++ b/src/queens_on_the_table_3.py @@ -0,0 +1,44 @@ +dictionary = [0, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596, 2279184] + +def queens_placement(SIDE): + + def trees_from_rows(row, columns, main_diagonal, collateral_diagonal): + + if row == SIDE: + return 1 + + count = 0 + + for column in range(SIDE): + main = row - column + collateral = row + column + + if (column not in columns and + (main) not in main_diagonal and + (collateral) not in collateral_diagonal): + + columns.add(column) + main_diagonal.add(main) + collateral_diagonal.add(collateral) + + count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal) + + columns.remove(column) + main_diagonal.remove(main) + collateral_diagonal.remove(collateral) + + return count + + return trees_from_rows(0, set(), set(), set()) + +USER_SIDE = int(input("Write the value of the side of the field: ")) + +if USER_SIDE <= len(dictionary): + print("Count of right placing: ", dictionary[USER_SIDE]) +else: + USER_ANSWER = input("Your number is large, and the calculation may take a VERY long time. Are you willing to wait? Y/N") + + if USER_ANSWER in 'Yy': + queens_placement(USER_SIDE) + else: + print("Enter a smaller side value please") \ No newline at end of file From 9c02a7d9ee714a5cde506f2ceef1c74ad27919c1 Mon Sep 17 00:00:00 2001 From: ermmmaks Date: Sun, 19 Oct 2025 22:05:33 +0300 Subject: [PATCH 5/6] Edited all requests --- src/complexity.md | 16 ++++---- src/dictionary_queens.py | 23 ++++++----- src/queens_on_the_table_1.py | 13 +++--- src/queens_on_the_table_2.py | 34 +++++++++------- src/queens_on_the_table_3.py | 78 +++++++++++++++++------------------- 5 files changed, 84 insertions(+), 80 deletions(-) diff --git a/src/complexity.md b/src/complexity.md index f231f99..5833ef2 100644 --- a/src/complexity.md +++ b/src/complexity.md @@ -1,16 +1,18 @@ + + Для первого, переборного решения: -1. Цикл из функции is_valid_place "for first_place in range(n):" имеет сложность O(N) +1. Цикл из функции is_valid_place "for first_place in range(n):" имеет сложность $O(N)$ 2. В функции queen_placement "permutations" занимает O(N!) 3. В добавок далее строится массив queens со сложностью O(N) - Итого: O(N * N! * N) ~ O(N^2 * N!) + Итого: $O(N \cdot N! \cdot N)$ ~ $O(N^2 \cdot N!)$ Для второго, рекурсивного решения: -1. В функции trees_from_rows вызывется цикл перебора всех колонок N раз => O(N) -2. Рекурсивный вызов со сменой строки занимает O(N - 1) (первую строку уже посчитали) +1. В функции trees_from_rows вызывется цикл перебора всех колонок N раз => $O(N)$ +2. Рекурсивный вызов со сменой строки занимает $O(N - 1)$ (первую строку уже посчитали) - Итого: O(N * (N - 1)) ~ O(N!) + Итого: $O(N \cdot (N - 1))$ Для третьего, чуть более оптимального решения со словарем: - I. Если N <= 15, то сложность программы - O(c) - II. Если N >= 15, то сложность как и у второй программы - O(N!) \ No newline at end of file + I. Если N <= 15, то сложность программы - $O(c)$ + II. Если N >= 15, то сложность как и у второй программы - $O(N \cdot (N - 1))$ \ No newline at end of file diff --git a/src/dictionary_queens.py b/src/dictionary_queens.py index 68f5fe0..126d4a6 100644 --- a/src/dictionary_queens.py +++ b/src/dictionary_queens.py @@ -1,36 +1,39 @@ variations = [] -def queens_placement(side): +def queens_placement(side): def trees_from_rows(row, columns, main_diagonal, collateral_diagonal): - if row == side: return 1 - + count = 0 for column in range(side): main = row - column collateral = row + column - if (column not in columns and - (main) not in main_diagonal and - (collateral) not in collateral_diagonal): - + if ( + column not in columns + and (main) not in main_diagonal + and (collateral) not in collateral_diagonal + ): columns.add(column) main_diagonal.add(main) collateral_diagonal.add(collateral) - count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal) + count += trees_from_rows( + row + 1, columns, main_diagonal, collateral_diagonal + ) columns.remove(column) main_diagonal.remove(main) collateral_diagonal.remove(collateral) - + return count return trees_from_rows(0, set(), set(), set()) -for i in range(16, 20): + +for i in range(15): variations.append(queens_placement(i)) print(variations) diff --git a/src/queens_on_the_table_1.py b/src/queens_on_the_table_1.py index 408f6e3..bc0220c 100644 --- a/src/queens_on_the_table_1.py +++ b/src/queens_on_the_table_1.py @@ -1,11 +1,11 @@ import itertools -USER_SIDE = int(input("Write the lenght of the side of the field: ")) +user_side = int(input("Write the lenght of the side of the field: ")) -def is_valid_place(positions, n): - for first_place in range(n): - for second_place in range(first_place + 1, n): +def is_valid_place(positions): + for first_place in range(user_side): + for second_place in range(first_place + 1, user_side): row1, column1 = positions[first_place] row2, column2 = positions[second_place] if abs(row1 - row2) == abs(column1 - column2): @@ -17,8 +17,9 @@ def queen_placement(side): count = 0 for rows in itertools.permutations(range(side)): queens = [(row, column) for row, column in enumerate(rows)] - if is_valid_place(queens, side): + if is_valid_place(queens): count += 1 return count -print("Count of right placing: ", queen_placement(USER_SIDE)) \ No newline at end of file + +print("Count of right placing: ", queen_placement(user_side)) diff --git a/src/queens_on_the_table_2.py b/src/queens_on_the_table_2.py index 4319ec4..ac9b8ef 100644 --- a/src/queens_on_the_table_2.py +++ b/src/queens_on_the_table_2.py @@ -1,34 +1,38 @@ -def queens_placement(SIDE): +def queens_placement(side): + columns = set() + main_diagonal = set() + collateral_diagonal = set() - def trees_from_rows(row, columns, main_diagonal, collateral_diagonal): - - if row == SIDE: + def trees_from_rows(row): + if row == side: return 1 - + count = 0 - for column in range(SIDE): + for column in range(side): main = row - column collateral = row + column - if (column not in columns and - (main) not in main_diagonal and - (collateral) not in collateral_diagonal): - + if ( + column not in columns + and (main) not in main_diagonal + and (collateral) not in collateral_diagonal + ): columns.add(column) main_diagonal.add(main) collateral_diagonal.add(collateral) - count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal) + count += trees_from_rows(row + 1) columns.remove(column) main_diagonal.remove(main) collateral_diagonal.remove(collateral) - + return count - return trees_from_rows(0, set(), set(), set()) + return trees_from_rows(0) + -USER_SIDE = int(input("Write the value of the side of the field: ")) +user_side = int(input("Write the value of the side of the field: ")) -print("Count of right placing: ", queens_placement(USER_SIDE)) \ No newline at end of file +print("Count of right placing: ", queens_placement(user_side)) diff --git a/src/queens_on_the_table_3.py b/src/queens_on_the_table_3.py index 489b524..1b8c056 100644 --- a/src/queens_on_the_table_3.py +++ b/src/queens_on_the_table_3.py @@ -1,44 +1,38 @@ -dictionary = [0, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596, 2279184] - -def queens_placement(SIDE): - - def trees_from_rows(row, columns, main_diagonal, collateral_diagonal): - - if row == SIDE: - return 1 - - count = 0 - - for column in range(SIDE): - main = row - column - collateral = row + column - - if (column not in columns and - (main) not in main_diagonal and - (collateral) not in collateral_diagonal): - - columns.add(column) - main_diagonal.add(main) - collateral_diagonal.add(collateral) - - count += trees_from_rows(row + 1, columns, main_diagonal, collateral_diagonal) - - columns.remove(column) - main_diagonal.remove(main) - collateral_diagonal.remove(collateral) - - return count - - return trees_from_rows(0, set(), set(), set()) - -USER_SIDE = int(input("Write the value of the side of the field: ")) - -if USER_SIDE <= len(dictionary): - print("Count of right placing: ", dictionary[USER_SIDE]) +dictionary = [ + 0, + 1, + 0, + 0, + 2, + 10, + 4, + 40, + 92, + 352, + 724, + 2680, + 14200, + 73712, + 365596, + 2279184, +] +from queens_on_the_table_2 import queens_placement + + +def queens_placement(side): + return trees_from_rows(0) + + +user_side = int(input("Write the value of the side of the field: ")) + +if user_side <= len(dictionary): + print("Count of right placing: ", dictionary[user_side]) else: - USER_ANSWER = input("Your number is large, and the calculation may take a VERY long time. Are you willing to wait? Y/N") - - if USER_ANSWER in 'Yy': - queens_placement(USER_SIDE) + user_answer = input( + "Your number is large, and the calculation may take a VERY long time. Are you willing to wait? Y/N" + ) + + if user_answer in "Yy": + queens_placement(user_side) else: - print("Enter a smaller side value please") \ No newline at end of file + print("Enter a smaller side value please") From 5fd0c58d53ea02d6d8fd22505fae568427bfeb06 Mon Sep 17 00:00:00 2001 From: ermmmaks Date: Sun, 19 Oct 2025 22:25:00 +0300 Subject: [PATCH 6/6] Fix the place .gitignore --- src/bubble_sort.py | 24 --------------- src/euclid++.py | 9 ------ src/hello.py | 1 - src/lexicographical_order_ruff.py | 39 ------------------------ src/lexicographical_order_ruff_edited.py | 39 ------------------------ 5 files changed, 112 deletions(-) delete mode 100644 src/bubble_sort.py delete mode 100644 src/euclid++.py delete mode 100644 src/hello.py delete mode 100644 src/lexicographical_order_ruff.py delete mode 100644 src/lexicographical_order_ruff_edited.py diff --git a/src/bubble_sort.py b/src/bubble_sort.py deleted file mode 100644 index 345fe6d..0000000 --- a/src/bubble_sort.py +++ /dev/null @@ -1,24 +0,0 @@ -def bubble_sort(arr): - n = len(arr) - - for i in range(n): - swapped = False - - for j in range(n - i - 1): - if arr[j] > arr[j + 1]: - temporary = arr[j] - arr[j] = arr[j + 1] - arr[j + 1] = temporary - swapped = True - if not swapped: - return arr - -len_arr = int(input("Введите длину массива: ")) -user_arr = [] - -for count in range(len_arr): - user_number = int(input(f"Число номер {count + 1}: ")) - user_arr.append(user_number) - -print("Сортировка выполнена!") -print(bubble_sort(user_arr) ) \ No newline at end of file diff --git a/src/euclid++.py b/src/euclid++.py deleted file mode 100644 index b3c6c5c..0000000 --- a/src/euclid++.py +++ /dev/null @@ -1,9 +0,0 @@ -def euclid(a, b): - if a == 0: - return (b, 0, 1) - gcd, x1, y1 = euclid(b % a, a) - koeff_x = y1 - (b//a) * x1 - koeff_y = x1 - return (gcd, koeff_x, koeff_y) - -print(euclid(240,46)) \ No newline at end of file diff --git a/src/hello.py b/src/hello.py deleted file mode 100644 index ed0f110..0000000 --- a/src/hello.py +++ /dev/null @@ -1 +0,0 @@ -print('hello') \ No newline at end of file diff --git a/src/lexicographical_order_ruff.py b/src/lexicographical_order_ruff.py deleted file mode 100644 index 406b26c..0000000 --- a/src/lexicographical_order_ruff.py +++ /dev/null @@ -1,39 +0,0 @@ -USER_STR1 = str(input("Введите первую строку: ")) -USER_STR2 = str(input("Введите вторую строку: ")) -ALPHABET = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[::-1] -MIN_LEN = min(len(USER_STR1), len(USER_STR2)) - -# 1) чем символ дальше от начала алфавита (z), тем он старше -# 2) чем меньше длина строки, тем она старше - - -def lexic_order(string1, string2): - for latin in string1 + string2: - if latin not in ALPHABET: - return "Используйте только латиницу!" - - for let in range(0, MIN_LEN): - let_s1 = string1[let] - let_s2 = string2[let] - - if (let_s1 != let_s2) or ( - let == MIN_LEN - 1 and let_s1 == let_s2 - ): # сравнение возможно, если: - # 1. всретились разные буквы - # 2. буквы одинаковые вплоть до последнего символа одной из строк - if (ALPHABET.index(let_s1) > ALPHABET.index(let_s2)) or ( - len(string1) < len(string2) - and (let_s1 == let_s2) - and let == MIN_LEN - 1 - ): - return "Первая строка старше, чем Вторая" - elif (ALPHABET.index(let_s2) > ALPHABET.index(let_s1)) or ( - len(string1) > len(string2) - and (let_s1 == let_s2) - and let == MIN_LEN - 1 - ): - return "Вторая строка старше, чем Первая" - return "Строки идентичны" - - -print(lexic_order(USER_STR1, USER_STR2)) diff --git a/src/lexicographical_order_ruff_edited.py b/src/lexicographical_order_ruff_edited.py deleted file mode 100644 index 406b26c..0000000 --- a/src/lexicographical_order_ruff_edited.py +++ /dev/null @@ -1,39 +0,0 @@ -USER_STR1 = str(input("Введите первую строку: ")) -USER_STR2 = str(input("Введите вторую строку: ")) -ALPHABET = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[::-1] -MIN_LEN = min(len(USER_STR1), len(USER_STR2)) - -# 1) чем символ дальше от начала алфавита (z), тем он старше -# 2) чем меньше длина строки, тем она старше - - -def lexic_order(string1, string2): - for latin in string1 + string2: - if latin not in ALPHABET: - return "Используйте только латиницу!" - - for let in range(0, MIN_LEN): - let_s1 = string1[let] - let_s2 = string2[let] - - if (let_s1 != let_s2) or ( - let == MIN_LEN - 1 and let_s1 == let_s2 - ): # сравнение возможно, если: - # 1. всретились разные буквы - # 2. буквы одинаковые вплоть до последнего символа одной из строк - if (ALPHABET.index(let_s1) > ALPHABET.index(let_s2)) or ( - len(string1) < len(string2) - and (let_s1 == let_s2) - and let == MIN_LEN - 1 - ): - return "Первая строка старше, чем Вторая" - elif (ALPHABET.index(let_s2) > ALPHABET.index(let_s1)) or ( - len(string1) > len(string2) - and (let_s1 == let_s2) - and let == MIN_LEN - 1 - ): - return "Вторая строка старше, чем Первая" - return "Строки идентичны" - - -print(lexic_order(USER_STR1, USER_STR2))