diff --git a/Game/Player.py b/Game/Player.py deleted file mode 100644 index e69de29..0000000 diff --git a/HNC/Arrays/Array/.idea/.gitignore b/HNC/Arrays/Array/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/HNC/Arrays/Array/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HNC/Arrays/Array/.idea/.name b/HNC/Arrays/Array/.idea/.name new file mode 100644 index 0000000..11a5d8e --- /dev/null +++ b/HNC/Arrays/Array/.idea/.name @@ -0,0 +1 @@ +main.py \ No newline at end of file diff --git a/HNC/Arrays/Array/.idea/Wiederholung.iml b/HNC/Arrays/Array/.idea/Wiederholung.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/HNC/Arrays/Array/.idea/Wiederholung.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HNC/Arrays/Array/.idea/inspectionProfiles/profiles_settings.xml b/HNC/Arrays/Array/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/HNC/Arrays/Array/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HNC/Arrays/Array/.idea/misc.xml b/HNC/Arrays/Array/.idea/misc.xml new file mode 100644 index 0000000..f03074d --- /dev/null +++ b/HNC/Arrays/Array/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HNC/Arrays/Array/.idea/modules.xml b/HNC/Arrays/Array/.idea/modules.xml new file mode 100644 index 0000000..ca1c8e9 --- /dev/null +++ b/HNC/Arrays/Array/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNC/Arrays/Array/main.py b/HNC/Arrays/Array/main.py new file mode 100644 index 0000000..20e3fbb --- /dev/null +++ b/HNC/Arrays/Array/main.py @@ -0,0 +1,148 @@ +import random + + +# Посчитать сумму всех положительных чисел +def sum_positive(array): + q = 0 + N = len(array) + for i in range(N): + if array[i] > 0: + q += array[i] + + return q + + +# Посчитать сумму всех отрицательных чисел +def sum_negative(array): + q = 0 + N = len(array) + for i in range(N): + if array[i] < 0: + q += array[i] + + return q + + +# Посчитать сумму всех положительных чисел, если в массиве есть отрицательное число +# Если отрицательных чисел нет, вернуть 0 +def sum_positive_if_negative(array): + q = 0 + N = len(array) + for i in range(N): + if array[i] > 0: + q += array[i] + if array[i] < 0: + return 0 + + return q + + +# Посчитать сумму всех отрицательных чисел, если в массиве есть число 1 +# Если числа 1 нет - посчитать сумму всех положительных чисел +def sum_negative_if_one(array): + q = int() + a = int() + for i in array: + if i == 1: + q += 1 + if q > 0: + break + if q > 0: + for i in array: + if i < 0: + a += i + else: + for i in array: + if i > 0: + a += i + return a + + + +# Посчитать сумму чисел ДО первого отрицательного числа (не включая его) +def sum_before_negative(array): + q = -1 + a = int() + for i in array: + q += 1 + if i < 0: + break + if q >= 0: + for i in array[:q]: + a += i + return a + + +# Посчитать сумму чисел ПОСЛЕ первого положительного числа (включая его) +def sum_after_positive(array): + q = -1 + a = int() + for i in array: + q += 1 + if i > 0: + break + if q >= 0: + for i in array[q:]: + a += i + return a + + +################################################# +def verifier(test_name, test_array, actual, expected): + print(test_name) + print(test_array) + if actual != expected: + print("=======> FAILED! <=======") + print(f"Got value <{actual}>") + print(f"Expected value is <{expected}>") + else: + print("PASSED") + print() + + +test_array10 = [] +test_array100 = [] +test_array1000 = [] + +for i in range(10): + test_array10.append(random.randint(0, 20) - 10) + test_array100.append(random.randint(0, 200) - 100) + test_array1000.append(random.randint(0, 2000) - 1000) + +tests = [test_array10, test_array100, test_array1000, [], [0]] + + +for i in range(len(tests)): + verifier(f"sum_positive TEST {i+1}", tests[i], sum_positive(tests[i]), sum([x for x in tests[i] if x > 0])) + +for i in range(len(tests)): + verifier(f"sum_negative TEST {i+1}", tests[i], sum_negative(tests[i]), sum([x for x in tests[i] if x < 0])) + +for i in range(len(tests)): + is_in = len([x for x in tests[i] if x < 0]) > 0 + if is_in: + verifier(f"sum_positive_if_negative TEST {i+1}", tests[i], sum_positive_if_negative(tests[i]), sum([x for x in tests[i] if x > 0])) + else: + verifier(f"sum_positive_if_negative TEST {i+1}", tests[i], sum_positive_if_negative(tests[i]), 0) + +for i in range(len(tests)): + is_in = len([x for x in tests[i] if x == 1]) > 0 + if is_in: + verifier(f"sum_negative_if_one TEST {i+1}", tests[i], sum_negative_if_one(tests[i]), sum([x for x in tests[i] if x < 0])) + else: + verifier(f"sum_negative_if_one TEST {i+1}", tests[i], sum_negative_if_one(tests[i]), sum([x for x in tests[i] if x > 0])) + +for i in range(len(tests)): + indices = [x for x in range(len(tests[i])) if tests[i][x] < 0] + if len(indices) > 0: + verifier(f"sum_before_negative TEST {i+1}", tests[i], sum_before_negative(tests[i]), sum(tests[i][:indices[0]])) + else: + verifier(f"sum_before_negative TEST {i+1}", tests[i], sum_before_negative(tests[i]), sum(tests[i])) + +for i in range(len(tests)): + indices = [x for x in range(len(tests[i])) if tests[i][x] > 0] + if len(indices) > 0: + verifier(f"sum_after_positive TEST {i+1}", tests[i], sum_after_positive(tests[i]), sum(tests[i][indices[0]:])) + else: + verifier(f"sum_after_positive TEST {i+1}", tests[i], sum_after_positive(tests[i]), 0) + diff --git a/HNC/Arrays/Array2/.idea/.gitignore b/HNC/Arrays/Array2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/HNC/Arrays/Array2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HNC/Arrays/Array2/.idea/.name b/HNC/Arrays/Array2/.idea/.name new file mode 100644 index 0000000..11a5d8e --- /dev/null +++ b/HNC/Arrays/Array2/.idea/.name @@ -0,0 +1 @@ +main.py \ No newline at end of file diff --git a/HNC/Arrays/Array2/.idea/inspectionProfiles/profiles_settings.xml b/HNC/Arrays/Array2/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/HNC/Arrays/Array2/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HNC/Arrays/Array2/.idea/misc.xml b/HNC/Arrays/Array2/.idea/misc.xml new file mode 100644 index 0000000..8432ad0 --- /dev/null +++ b/HNC/Arrays/Array2/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HNC/Arrays/Array2/.idea/modules.xml b/HNC/Arrays/Array2/.idea/modules.xml new file mode 100644 index 0000000..e15ec35 --- /dev/null +++ b/HNC/Arrays/Array2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNC/Arrays/Array2/.idea/pythonProject.iml b/HNC/Arrays/Array2/.idea/pythonProject.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/HNC/Arrays/Array2/.idea/pythonProject.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HNC/Arrays/Array2/main.py b/HNC/Arrays/Array2/main.py new file mode 100644 index 0000000..ea37dab --- /dev/null +++ b/HNC/Arrays/Array2/main.py @@ -0,0 +1,45 @@ +def mymin(array): + a = A[0] + for b in A: + if (a > b): + a = b + + return a + + +def mymax(array): + a = A[0] + for b in A: + if (a < b): + a = b + + return a + + +def mysum(array): + b = 0 + for a in A: + b += a + + return b + + +A = [1, 4, 3, 7, 2, 9, 1, 10] +result = mymin(A) +print(result) + +A = [1, 4, 3, 7, 2, 9, 1, 10] +result = mymax(A) +print(result) + +A = [1, 4, 3, 7, 2, 9, 1, 10] +result = mysum(A) +print(result) + + + + + + + + diff --git a/HNC/Exercises/CreateClass/.idea/.gitignore b/HNC/Exercises/CreateClass/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/HNC/Exercises/CreateClass/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HNC/Exercises/CreateClass/.idea/CreateClass.iml b/HNC/Exercises/CreateClass/.idea/CreateClass.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/HNC/Exercises/CreateClass/.idea/CreateClass.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HNC/Exercises/CreateClass/.idea/inspectionProfiles/profiles_settings.xml b/HNC/Exercises/CreateClass/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/HNC/Exercises/CreateClass/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HNC/Exercises/CreateClass/.idea/misc.xml b/HNC/Exercises/CreateClass/.idea/misc.xml new file mode 100644 index 0000000..548a8d8 --- /dev/null +++ b/HNC/Exercises/CreateClass/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HNC/Exercises/CreateClass/.idea/modules.xml b/HNC/Exercises/CreateClass/.idea/modules.xml new file mode 100644 index 0000000..e0e2fa9 --- /dev/null +++ b/HNC/Exercises/CreateClass/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNC/Exercises/CreateClass/ClassRectangle.py b/HNC/Exercises/CreateClass/ClassRectangle.py new file mode 100644 index 0000000..53b4e4e --- /dev/null +++ b/HNC/Exercises/CreateClass/ClassRectangle.py @@ -0,0 +1,19 @@ +class Rectangle(): + def __init__(self, a, b): + self.a = a + self.b = b + + + def calculateArea(self): + area = int(self.a * self.b) + print('Die Fläche hat den Wert: ', area) + + + def calculateCircumference(self): + circumference = int(2*self.a + 2*self.b) + print('Der Umfang hat den Wert: ', circumference) + + + + + diff --git a/HNC/Exercises/CreateClass/ClassTriangle.py b/HNC/Exercises/CreateClass/ClassTriangle.py new file mode 100644 index 0000000..1f27c88 --- /dev/null +++ b/HNC/Exercises/CreateClass/ClassTriangle.py @@ -0,0 +1,18 @@ +class Triangle(): + def __init__(self, a, b, c): + self.a = a + self.b = b + self.c = c + + + def calculateArea(self): + area = int((self.a + self.b + self.c)/2) + print('Die Fläche hat den Wert: ', area) + + + def calculateCircumference(self): + circumference = int(self.a + self.b + self.c) + print('Der Umfang hat den Wert: ', circumference) + + + diff --git a/HNC/Exercises/CreateClass/main.py b/HNC/Exercises/CreateClass/main.py new file mode 100644 index 0000000..2db2060 --- /dev/null +++ b/HNC/Exercises/CreateClass/main.py @@ -0,0 +1,20 @@ +from ClassRectangle import Rectangle +from ClassTriangle import Triangle + +triangle1 = Triangle(36, 12, 2) +triangle1.calculateArea() + +triangle2 = Triangle(3, 9, 5) +triangle2.calculateCircumference() + +triangle3 = Triangle(4, 12, 2) +triangle3.calculateArea() + +rectangle1 = Rectangle(6, 6) +rectangle1.calculateArea() + +rectangle2 = Rectangle(1, 12) +rectangle2.calculateCircumference() + +rectangle3 = Rectangle(36, 21) +rectangle3.calculateArea() \ No newline at end of file diff --git a/HNC/Exercises/Menu/.idea/.gitignore b/HNC/Exercises/Menu/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/HNC/Exercises/Menu/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HNC/Exercises/Menu/.idea/inspectionProfiles/profiles_settings.xml b/HNC/Exercises/Menu/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/HNC/Exercises/Menu/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HNC/Exercises/Menu/.idea/misc.xml b/HNC/Exercises/Menu/.idea/misc.xml new file mode 100644 index 0000000..ae0380c --- /dev/null +++ b/HNC/Exercises/Menu/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HNC/Exercises/Menu/.idea/modules.xml b/HNC/Exercises/Menu/.idea/modules.xml new file mode 100644 index 0000000..fdd8fdf --- /dev/null +++ b/HNC/Exercises/Menu/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNC/Exercises/Menu/.idea/pythonProject1.iml b/HNC/Exercises/Menu/.idea/pythonProject1.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/HNC/Exercises/Menu/.idea/pythonProject1.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HNC/Exercises/Menu/Homework.py b/HNC/Exercises/Menu/Homework.py new file mode 100644 index 0000000..f0b0648 --- /dev/null +++ b/HNC/Exercises/Menu/Homework.py @@ -0,0 +1,22 @@ +def main_Sum(array): + sum = 0 + for a in array: + sum += a + return sum + + +def main_Max(array): + max = array[0] + for b in array: + if b > max: + max = b + return max + + +def main_Min(array): + min = array[0] + for b in array: + if b <= min: + min = b + return min + diff --git a/HNC/Exercises/Menu/Homework1.py b/HNC/Exercises/Menu/Homework1.py new file mode 100644 index 0000000..c3d075e --- /dev/null +++ b/HNC/Exercises/Menu/Homework1.py @@ -0,0 +1,37 @@ +def number_add_to_array(array): + number1 = input("Gebe eine ganze Zahl ein: ") + if number1.lstrip("-").isnumeric(): + array.append(int(number1)) + else: + print("Deine Eingabe ist keine ganze Zahl!") + + +def number_remove_from_array(array): + if len(array) > 0: + array.pop() + + +def my_array_menu(array): + print("Dein Array", array) + print("1. Einfügen") + print("2. Löschen") + print("3. Beenden") + + +def my_array_loop(array): + while True: + my_array_menu(array) + inp = input() + if inp.isnumeric(): + op = int(inp) + if 1 <= op <= 3: + if op == 1: + number_add_to_array(array) + elif op == 2: + number_remove_from_array(array) + elif op == 3: + break + else: + print("Wähle eien Nummer aus!") + else: + print("Gebe eine Zahl ein!") \ No newline at end of file diff --git a/HNC/Exercises/Menu/Homework1_1.py b/HNC/Exercises/Menu/Homework1_1.py new file mode 100644 index 0000000..01d7bd2 --- /dev/null +++ b/HNC/Exercises/Menu/Homework1_1.py @@ -0,0 +1,51 @@ +from Homework import main_Sum +from Homework import main_Max +from Homework import main_Min +from Homework1 import my_array_loop +from Homework1_2 import insertionsort + + +def main_menu(): + print("Dein Array", array) + print("1. Сумма") + print("2. Максимум") + print("3. Минимум") + print("4. InsertionSort") + print("5. Array") + print("6. Выход") + + +array = [] + +while True: + main_menu() + inp = input() + if inp.isnumeric(): + op = int(inp) + if 1 <= op <= 6: + if op == 1: + if len(array) > 0: + print(main_Sum(array)) + else: + print("Dein Array ist leer!!!") + elif op == 2: + if len(array) > 0: + print(main_Max(array)) + else: + print("Dein Array ist leer!!!") + elif op == 3: + if len(array) > 0: + print(main_Min(array)) + else: + print("Dein Array ist leer!!!") + elif op == 4: + insertionsort(array) + elif op == 5: + my_array_loop(array) + elif op == 6: + print("Beenden") + break + else: + print("Wähle eine Nummer!") + else: + print("Gebe eine Nummer ein!") \ No newline at end of file diff --git a/HNC/Exercises/Menu/Homework1_2.py b/HNC/Exercises/Menu/Homework1_2.py new file mode 100644 index 0000000..9d4dafe --- /dev/null +++ b/HNC/Exercises/Menu/Homework1_2.py @@ -0,0 +1,7 @@ +def insertionsort(array): + for i in range(1, len(array)): + j = i + while array[j - 1] > array[j] and j > 0: + array[j - 1], array[j] = array[j], array[j - 1] + j -= 1 + diff --git a/HNC/Exercises/Menu/main.py b/HNC/Exercises/Menu/main.py new file mode 100644 index 0000000..fd40910 --- /dev/null +++ b/HNC/Exercises/Menu/main.py @@ -0,0 +1,4 @@ + + + + diff --git a/HNC/Exercises/Repeat_Exercise/word_count.py b/HNC/Exercises/Repeat_Exercise/word_count.py new file mode 100644 index 0000000..da7665f --- /dev/null +++ b/HNC/Exercises/Repeat_Exercise/word_count.py @@ -0,0 +1,32 @@ +def count(): + sentence = "Я пришел, я ушел, я нашел" + str1 = 'Я' + str2 = 'я' + if str1.lower() == str2.lower(): + count1 = sentence.count(str1) + count2 = sentence.count(str2) + print("The count of 'Я' is", count1+count2) + + sentence2 = sentence.count('пришел') + sentence3 = sentence.count('ушел') + sentence4 = sentence.count('нашел') + + + print("The count of 'пришел' is", sentence2) + print("The count of 'ушел' is", sentence3) + print("The count of 'нашел' is", sentence4) + +count() + +# from collections import defaultdict + +# test_sentence = ["Я", "пришел", "я", "ушел", "я", "нашел"] + +# print("The original sentence is : " + str(test_sentence)) + +# res = defaultdict(int) + +# for count in test_sentence: +# res[count.lower()] += 1 + +# print("Strings Frequency : " +str(dict(res))) \ No newline at end of file diff --git a/HNC/Exercises/Selfmade_Testing/testing.py b/HNC/Exercises/Selfmade_Testing/testing.py new file mode 100644 index 0000000..8515ff0 --- /dev/null +++ b/HNC/Exercises/Selfmade_Testing/testing.py @@ -0,0 +1,17 @@ +test_cases = [ + ("Sobaka", 1, 2), + ("Koshka", 2, 3), + ("Ezhik", 3, 4) +] + +def print_zhivotny(mnogo_zhivotny): + for zhivotny in mnogo_zhivotny: + print("=" * 20) + test_name = zhivotny[0] + test_actual = zhivotny[1] + test_expected = zhivotny[2] + + print(test_name, test_actual, test_expected) + print("=" * 20) + +print_zhivotny(test_cases) \ No newline at end of file diff --git a/HNC/Exercises/Unit_Test/.idea/.gitignore b/HNC/Exercises/Unit_Test/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/HNC/Exercises/Unit_Test/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HNC/Exercises/Unit_Test/.idea/.name b/HNC/Exercises/Unit_Test/.idea/.name new file mode 100644 index 0000000..11a5d8e --- /dev/null +++ b/HNC/Exercises/Unit_Test/.idea/.name @@ -0,0 +1 @@ +main.py \ No newline at end of file diff --git a/HNC/Exercises/Unit_Test/.idea/Unit_Test.iml b/HNC/Exercises/Unit_Test/.idea/Unit_Test.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/HNC/Exercises/Unit_Test/.idea/Unit_Test.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HNC/Exercises/Unit_Test/.idea/inspectionProfiles/profiles_settings.xml b/HNC/Exercises/Unit_Test/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/HNC/Exercises/Unit_Test/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HNC/Exercises/Unit_Test/.idea/misc.xml b/HNC/Exercises/Unit_Test/.idea/misc.xml new file mode 100644 index 0000000..d1bc9ff --- /dev/null +++ b/HNC/Exercises/Unit_Test/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HNC/Exercises/Unit_Test/.idea/modules.xml b/HNC/Exercises/Unit_Test/.idea/modules.xml new file mode 100644 index 0000000..8688c8e --- /dev/null +++ b/HNC/Exercises/Unit_Test/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNC/Exercises/Unit_Test/main.py b/HNC/Exercises/Unit_Test/main.py new file mode 100644 index 0000000..62f73e2 --- /dev/null +++ b/HNC/Exercises/Unit_Test/main.py @@ -0,0 +1,182 @@ +# Сумма элементов массива +def sum_array(array): + # Что должна возвращать функция? + sum = 0 + + # Проводим вычисления + for a in array: + sum = sum + a + + # Вернуть значение + return sum + + +# Из суммы элементов с четным индексом вычесть элементы с нечетным индексом (0 - четный) +def sum_diff_array(array): + # Что должна возвращать функция? + result = 0 + + # Проводим вычисления + for e in range(len(array)): + if e % 2 == 0: + result = result + array[e] + else: + result = result - array[e] + + # Вернуть значение + return result + + +# Максимальное число из массива помножить на минимальное число из массива +def max_mul_min_array(array): + sum = 0 + + +# Развернуть строку (например "Abc" -> "cbA") +def invert_string(string): + return string[::-1] + + +# Все буквы сделать заглавными (например "aBc" -> "ABC") +def to_upper_string(string): + # Что должна возвращать функция? + str1 = "" + + # Проводим вычисления + for c in string: + # Проверить, какая буква + if 97 <= ord(c) <= 122: + # Если маленькая - то превращаем в большую и добавляем в итоговую строку + str1 += chr(ord(c) - 32) + else: + # Если уже большая - то перенимаем букву в итоговую строку + # А если вообще не буква?! - Также перенимаем без изменений + str1 += c + + # Вернуть значение + return str1 + + +# Все буквы сделать прописными (например "aBc" -> "abc") +def to_lower_string(string): + str1 = "" + + for x in string: + if 65 <= ord(x) <= 90: + str1 += chr(ord(x) + 32) + else: + str1 += x + + return str1 + + +# Проверить, является ли строка палиндромом (независимо от больших/маленьких букв) +def check_palindrome(string): + new_string = to_upper_string(string) + return new_string == invert_string(new_string) + + +# Проверить, является ли строка палиндромом (независимо от больших/маленьких букв и знаков пунктуации/пробелов) +def check_palindrome_escaped(string): + pass + + +# "Ручной" аналог функции split() +def split_string(string, separator): + pass + + +# "Ручной" аналог функции join() +def join_array(array, separator): + pass + + +################################################# +def verifier(test_name, actual, expected): + print(test_name) + if actual != expected: + print("=======> FAILED! <=======") + print(f"Got value <{actual}>") + print(f"Expected value is <{expected}>") + else: + print("PASSED") + print() + + +test_array1 = [6, 4, 7, -3, 6, -1, 5, 8, 4, -6, 8, 3, 6, 4, -7, 21, 6, 4, -1, 1] +test_array2 = [987, 342, -876, 182, -6534, 998, -11, 334, 0, 6654, -9901, 333, 111, 664] +test_array3 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10] + +test_string1 = "The World is not enough" +test_string2 = "Testing is key" + +test_palindrome1 = "Sir, I demand, I am a maid named Iris" +test_palindrome2 = "Satire: Veritas" +test_palindrome3 = "Saippuakivikauppias" + +test_split1 = "1, 2, 3, 4, 5, 6, 7, 8, 9" +test_split2 = "1 2 3 4 5 6 7 8 9" +test_split3 = "bagahajemanbdneorijahdhrea4" + +test_array4 = test_split1.split(',') +test_array5 = test_split2.split(' ') +test_array6 = test_split3.split('a') + +sum_array_tests = [test_array1, test_array2, test_array3, [], [0]] +string_tests = [test_string1, test_string2, test_palindrome1, test_palindrome2, test_palindrome3, ''] +palindrome_tests = [test_string1, test_string2, test_palindrome1, test_palindrome2, test_palindrome3, ''] +split_string_tests = [test_split1, test_split2, test_split3, test_string1, test_string2, ''] +join_array_tests = [test_array4, test_array5, test_array6, [], ['']] + +for i in range(len(sum_array_tests)): + verifier(f"SUM_ARRAY TEST {i+1}", sum_array(sum_array_tests[i]), sum(sum_array_tests[i])) + +for i in range(len(sum_array_tests)): + verifier(f"SUM_DIFF_ARRAY TEST {i+1}", sum_diff_array(sum_array_tests[i]), sum(sum_array_tests[i][0::2]) - sum(sum_array_tests[i][1::2])) + +for i in range(len(sum_array_tests)): + if len(sum_array_tests[i]) == 0: + verifier(f"MAX_MUL_MIN_ARRAY TEST {i + 1}", max_mul_min_array(sum_array_tests[i]), 0) + else: + verifier(f"MAX_MUL_MIN_ARRAY TEST {i+1}", max_mul_min_array(sum_array_tests[i]), max(sum_array_tests[i]) * min(sum_array_tests[i])) + +for i in range(len(string_tests)): + verifier(f"INVERT_STRING TEST {i+1}", invert_string(string_tests[i]), string_tests[i][::-1]) + +for i in range(len(string_tests)): + verifier(f"TO_UPPER_STRING TEST {i+1}", to_upper_string(string_tests[i]), string_tests[i].upper()) + +for i in range(len(string_tests)): + verifier(f"TO_LOWER_STRING TEST {i+1}", to_lower_string(string_tests[i]), string_tests[i].lower()) + +for i in range(len(palindrome_tests)): + verifier(f"CHECK_PALINDROME TEST {i+1}", + check_palindrome(palindrome_tests[i]), + (palindrome_tests[i].lower() == palindrome_tests[i].lower()[::-1])) + +for i in range(len(palindrome_tests)): + val = "".join(e for e in palindrome_tests[i] if e.isalpha()) + verifier(f"CHECK_PALINDROME_ESCAPED TEST {i+1}", + check_palindrome_escaped(palindrome_tests[i]), + (val.lower() == val.lower()[::-1])) + +for i in range(len(split_string_tests)): + separator = ',' + verifier(f"SPLIT_STRING (SEPARATOR='{separator}') TEST {i+1}", + split_string(split_string_tests[i], separator), + split_string_tests[i].split(separator)) + +for i in range(len(split_string_tests)): + separator = ' ' + verifier(f"SPLIT_STRING (SEPARATOR='{separator}') TEST {i+1}", + split_string(split_string_tests[i], separator), + split_string_tests[i].split(separator)) + +for i in range(len(join_array_tests)): + separator = '#' + verifier(f"JOIN_ARRAY (SEPARATOR='{separator}') TEST {i+1}", join_array(join_array_tests[i], separator), separator.join(join_array_tests[i])) + +for i in range(len(join_array_tests)): + separator = '' + verifier(f"JOIN_ARRAY (SEPARATOR='{separator}') TEST {i+1}", join_array(join_array_tests[i], separator), separator.join(join_array_tests[i])) + diff --git a/HNC/Ladders/Game/.idea/.gitignore b/HNC/Ladders/Game/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/HNC/Ladders/Game/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/HNC/Ladders/Game/.idea/Game.iml b/HNC/Ladders/Game/.idea/Game.iml new file mode 100644 index 0000000..8437fe6 --- /dev/null +++ b/HNC/Ladders/Game/.idea/Game.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNC/Ladders/Game/.idea/inspectionProfiles/profiles_settings.xml b/HNC/Ladders/Game/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/HNC/Ladders/Game/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/HNC/Ladders/Game/.idea/misc.xml b/HNC/Ladders/Game/.idea/misc.xml new file mode 100644 index 0000000..dc9ea49 --- /dev/null +++ b/HNC/Ladders/Game/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/HNC/Ladders/Game/.idea/modules.xml b/HNC/Ladders/Game/.idea/modules.xml new file mode 100644 index 0000000..4e01bd3 --- /dev/null +++ b/HNC/Ladders/Game/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HNC/Ladders/Game/.idea/vcs.xml b/HNC/Ladders/Game/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/HNC/Ladders/Game/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HNC/Ladders/Game/Player.py b/HNC/Ladders/Game/Player.py new file mode 100644 index 0000000..2625173 --- /dev/null +++ b/HNC/Ladders/Game/Player.py @@ -0,0 +1,7 @@ +class Player: + + def __init__(self, color): + self.color = color + self.position = -1 + self.skip = False + self.dices = [] \ No newline at end of file diff --git a/Game/game.py b/HNC/Ladders/Game/game.py similarity index 100% rename from Game/game.py rename to HNC/Ladders/Game/game.py diff --git a/Game/main.py b/HNC/Ladders/Game/main.py similarity index 96% rename from Game/main.py rename to HNC/Ladders/Game/main.py index b29cf7a..b3e9bd0 100644 --- a/Game/main.py +++ b/HNC/Ladders/Game/main.py @@ -1,5 +1,3 @@ - - from Player import Player @@ -25,9 +23,6 @@ def load(file): return b - - - def level_menu(): for i in range(1, len(levels) + 1): print(f'{i}. Level {i}') @@ -130,6 +125,6 @@ def run(level, runs): print() -levels = ['level1.txt', 'level2.txt', 'level3.txt', 'level4.txt', 'level5.txt', 'level6.txt'] +levels = ['level_1.txt', 'level_2.txt', 'level_3.txt', 'level_4.txt', 'level_5.txt'] #random.seed() main_menu_loop() \ No newline at end of file diff --git a/Level/level_1.txt b/HNC/Ladders/Level/level_1.txt similarity index 100% rename from Level/level_1.txt rename to HNC/Ladders/Level/level_1.txt diff --git a/Level/level_2.txt b/HNC/Ladders/Level/level_2.txt similarity index 100% rename from Level/level_2.txt rename to HNC/Ladders/Level/level_2.txt diff --git a/Level/level_3.txt b/HNC/Ladders/Level/level_3.txt similarity index 100% rename from Level/level_3.txt rename to HNC/Ladders/Level/level_3.txt diff --git a/Level/level_4.txt b/HNC/Ladders/Level/level_4.txt similarity index 100% rename from Level/level_4.txt rename to HNC/Ladders/Level/level_4.txt diff --git a/Level/level_5.txt b/HNC/Ladders/Level/level_5.txt similarity index 100% rename from Level/level_5.txt rename to HNC/Ladders/Level/level_5.txt diff --git a/test.py b/test.py deleted file mode 100644 index e69de29..0000000