From f23eb4841d49d9055362fa8679306b5ce5526bc5 Mon Sep 17 00:00:00 2001 From: tovarishchgamma Date: Thu, 29 Feb 2024 22:25:18 +0300 Subject: [PATCH] Lab5 to py + module2 --- python/src/module2/tusc1.py | 11 +++++++++++ python/src/module2/tusc2.py | 16 ++++++++++++++++ python/src/module2/tusc3.py | 30 +++++++++++++++++++++++++++++ python/src/module2/tusc4.py | 28 +++++++++++++++++++++++++++ python/src/module2/tusc5.py | 38 +++++++++++++++++++++++++++++++++++++ python/src/module2/tusc6.py | 15 +++++++++++++++ python/src/module2/tusc7.py | 23 ++++++++++++++++++++++ python/tests/Lab5.py | 27 ++++++++++++++++++++++++++ python/tests/__init__.py | 0 python/tests/main.py | 10 ++++++++++ python/tests/test_main.py | 37 ------------------------------------ 11 files changed, 198 insertions(+), 37 deletions(-) create mode 100644 python/src/module2/tusc1.py create mode 100644 python/src/module2/tusc2.py create mode 100644 python/src/module2/tusc3.py create mode 100644 python/src/module2/tusc4.py create mode 100644 python/src/module2/tusc5.py create mode 100644 python/src/module2/tusc6.py create mode 100644 python/src/module2/tusc7.py create mode 100644 python/tests/Lab5.py delete mode 100644 python/tests/__init__.py create mode 100644 python/tests/main.py delete mode 100644 python/tests/test_main.py diff --git a/python/src/module2/tusc1.py b/python/src/module2/tusc1.py new file mode 100644 index 0000000..de8faf9 --- /dev/null +++ b/python/src/module2/tusc1.py @@ -0,0 +1,11 @@ +a = int(input()) +da = [int(vr) for vr in input().split()] +const = 0 +for l in range(a-1): + for i in range(a-1): + if da[i] > da[i+1]: + const +=1 + da[i], da[i+1] = da[i+1], da[i] + print(' '.join(map(str, da))) +if const == 0: + print(0) \ No newline at end of file diff --git a/python/src/module2/tusc2.py b/python/src/module2/tusc2.py new file mode 100644 index 0000000..24d34ae --- /dev/null +++ b/python/src/module2/tusc2.py @@ -0,0 +1,16 @@ +a = int(input()) +l = 0 +spisok = [] + +while l < a: + list = [int(n) for n in input().split()] + spisok.append(list) + l += 1 + +for r in range(a-1): + for i in range(a-1): + if spisok[i][1] < spisok[i+1][1] or (spisok[i][1] == spisok[i+1][1] and spisok[i][0] > spisok[i+1][0]): + spisok[i], spisok[i+1] = spisok[i+1], spisok[i] + +for list in spisok: + print(' '.join(map(str, list))) \ No newline at end of file diff --git a/python/src/module2/tusc3.py b/python/src/module2/tusc3.py new file mode 100644 index 0000000..d725874 --- /dev/null +++ b/python/src/module2/tusc3.py @@ -0,0 +1,30 @@ +def soed2sp(a, b, Ind): + const = [] + i = j = 0 + while i 1: + mid = len(a) // 2 + left = a[:mid] + right = a[mid:] + soedsort(left) + soedsort(right) + i = j = l = 0 + while i < len(left) and j < len(right): + if left[i] < right[j]: + a[l] = left[i] + i += 1 + else: + a[l] = right[j] + j += 1 + l += 1 + while i < len(left): + a[l] = left[i] + i += 1 + l += 1 + while j < len(right): + a[l] = right[j] + j += 1 + l += 1 + +def sortbis(a): + if len(a) <= 1: + return a + else: + st = a[0] + men = [x for x in a[1:] if x <= st] + bol = [x for x in a[1:] if x > st] + return sortbis(men) + [st] + sortbis(bol) + +n = int(input()) +num = list(map(int, input().split())) +soedsort(num) +result = [] \ No newline at end of file diff --git a/python/src/module2/tusc6.py b/python/src/module2/tusc6.py new file mode 100644 index 0000000..1bbda95 --- /dev/null +++ b/python/src/module2/tusc6.py @@ -0,0 +1,15 @@ +vid = int(input()) +listtov = [int(n) for n in input().split()] +b = int(input()) +list = [int(n) for n in input().split()] +sche = [0]*(vid+1) +for i in list: + sche[i]+=1 +sche.pop(0) +stopsche = 0 +while stopsche < vid: + if sche[stopsche] > listtov[stopsche]: + print("yes") + else: + print("no") + stopsche += 1 \ No newline at end of file diff --git a/python/src/module2/tusc7.py b/python/src/module2/tusc7.py new file mode 100644 index 0000000..582be6b --- /dev/null +++ b/python/src/module2/tusc7.py @@ -0,0 +1,23 @@ +def sortr(list): + cor = [[] for _ in range(10)] + mlen = max(len(x) for x in list) + print("Initial array:\n" + ", ".join(list)) + for p in range(mlen): + print("**********") + print(f"Phase {p + 1}") + for i in range(10): + for l in list: + if len(l) > p: + if int(l[-p-1]) == i: + cor[i].append(l) + print(f"Bucket {i}: {', '.join(cor[i]) if cor[i] else 'empty'}") + + list = [x for b in cor for x in b] + cor = [[] for _ in range(10)] + + print("**********") + print("Sorted array:\n" + ", ".join(list)) + +n = int(input()) +list = [input() for _ in range(n)] +sortr(list) \ No newline at end of file diff --git a/python/tests/Lab5.py b/python/tests/Lab5.py new file mode 100644 index 0000000..4dcc13b --- /dev/null +++ b/python/tests/Lab5.py @@ -0,0 +1,27 @@ +class Mouse(): + name = None + age = None + color = None + gender = None + + def __init__(self, name: str, age: int, color: str, gender: str): + self.Check(name, age, color, gender) + self.name = name + self.age = age + self.color = color + self.gender = gender + + def Check(self, name: str, age: int, color: str, gender: str ): + if not name.isalpha(): + raise TypeError("Ошибка, неверный тип данных для параметра name. Ожидается строка.") + elif age < 0 or age > 5: + raise ValueError("Ошибка, неверно указано значение возраста") + elif not color.isalpha(): + raise TypeError("Ошибка, неверный тип данных для параметра color. Ожидается строка.") + elif not gender.isalpha(): + raise TypeError("Ошибка, неверный тип данных для параметра gender. Ожидается строка.") + def get(self): + if self.age == None or self.gender == None or self.color == None or self.age == None: + print("Есть неуказанные значения в параметрах человека: None, попробуйте пересоздать Мыша!") + else: + print(f"Мышонок создан.\nИмя мыша: {self.name}\nВозраст: {self.age} лет\nПол: {self.gender} \nЦвет: {self.color} ") \ No newline at end of file diff --git a/python/tests/__init__.py b/python/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/python/tests/main.py b/python/tests/main.py new file mode 100644 index 0000000..36e7d65 --- /dev/null +++ b/python/tests/main.py @@ -0,0 +1,10 @@ +import Lab5 as laba + +Mouse = input("Введите имя мыша: ") +Age = int(input("Введите возраст мыша: ")) +Gender = input("Введите пол мыша: ") +Color = input("Введите цвет мыша: ") + +Mysh1 = laba.Mouse(Mouse, Age, Color, Gender) + +Mysh1.get() diff --git a/python/tests/test_main.py b/python/tests/test_main.py deleted file mode 100644 index 0280a2e..0000000 --- a/python/tests/test_main.py +++ /dev/null @@ -1,37 +0,0 @@ -import unittest -from src import main - - -class SummTests(unittest.TestCase): - - def test_positive(self): - res = main.summ(2, 3) - self.assertEqual(5, res) - - def test_zero(self): - res = main.summ(0, 0) - self.assertEqual(0, res) - - def test_one_negative(self): - res = main.summ(-2, 3) - self.assertEqual(1, res) - - def test_both_negative(self): - res = main.summ(-2, -4) - self.assertEqual(-6, res) - - def test_one_negative_zero_res(self): - res = main.summ(-2, 2) - self.assertEqual(0, res) - - def test_one_negative_and_text(self): - try: - main.summ(-2, "2") - except: - self.assertTrue(True) - return - self.fail() - - -if __name__ == '__main__': - unittest.main()