From dc1b77ef196417f71d41b2f45c7ce8cf34daf727 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Tue, 4 Oct 2022 15:19:31 +0300 Subject: [PATCH 01/17] =?UTF-8?q?4.5=20=D0=BD=D0=B5=20=D0=BC=D0=BE=D0=B3?= =?UTF-8?q?=D1=83=20=D0=BD=D0=B0=D0=B9=D1=82=D0=B8=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BA=D1=83,=20=D0=BF=D0=BE=D0=B4=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=D0=B6=D0=B8=D1=82=D0=B5=20Traceback=20(most=20recent=20call=20?= =?UTF-8?q?last):=20=20=20File=20"C:\Users\=D0=95=D0=B2=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9\Desktop\git\PythonCourse2.0=5FAugust22\Practice\Ka?= =?UTF-8?q?trashova\les4.5.py",=20line=204,=20in=20=20=20=20=20=20?= =?UTF-8?q?c=20=3D=20random.randint(a,=20b)=20NameError:=20name=20'random'?= =?UTF-8?q?=20is=20not=20defined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/Katrashova/les4.5.py | 19 +++++++++++++++++++ Practice/RybnikovS/Day 04/Task 03.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Practice/Katrashova/les4.5.py diff --git a/Practice/Katrashova/les4.5.py b/Practice/Katrashova/les4.5.py new file mode 100644 index 0000000..3f7d0b7 --- /dev/null +++ b/Practice/Katrashova/les4.5.py @@ -0,0 +1,19 @@ +a = input("Введите начало диапазона: ") +b = input("Введите конец диапазона: ") +print("Число загадано в указанном диапазоне") +c = random.randint(a, b) + + +while True: + x = input("Попробуй отгадать моё число ") + if not x.isdecimal(): + break + x = int(x) + if x < c: + print("Введённое число меньше загаданного.") + elif x > c: + print("Введённое число больше загаданного.") + else: + print("Поздравляю, Вы угадали!") + + diff --git a/Practice/RybnikovS/Day 04/Task 03.py b/Practice/RybnikovS/Day 04/Task 03.py index 541a247..cb28013 100644 --- a/Practice/RybnikovS/Day 04/Task 03.py +++ b/Practice/RybnikovS/Day 04/Task 03.py @@ -1,4 +1,4 @@ -s = "" + s = "" while True: x = input("Введите символ: ") if x.upper() == "STOP": From 67a7f57cc40093ebbd1c224a3c0ab3fa282d17f4 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Tue, 4 Oct 2022 19:08:57 +0300 Subject: [PATCH 02/17] 4.5 --- Practice/Katrashova/les4.5.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Practice/Katrashova/les4.5.py b/Practice/Katrashova/les4.5.py index 3f7d0b7..e9a57a1 100644 --- a/Practice/Katrashova/les4.5.py +++ b/Practice/Katrashova/les4.5.py @@ -1,5 +1,7 @@ -a = input("Введите начало диапазона: ") -b = input("Введите конец диапазона: ") +import random + +a = int(input("Введите начало диапазона: ")) +b = int(input("Введите конец диапазона: ")) print("Число загадано в указанном диапазоне") c = random.randint(a, b) @@ -7,7 +9,8 @@ while True: x = input("Попробуй отгадать моё число ") if not x.isdecimal(): - break + print("Введено не число") + continue x = int(x) if x < c: print("Введённое число меньше загаданного.") @@ -15,5 +18,6 @@ print("Введённое число больше загаданного.") else: print("Поздравляю, Вы угадали!") + break From 9a321f941f69426fb4de4eb9f4fc1c38a172f604 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Tue, 4 Oct 2022 21:23:28 +0300 Subject: [PATCH 03/17] 4.6 --- Practice/Katrashova/lesson4/les 4.6.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Practice/Katrashova/lesson4/les 4.6.py diff --git a/Practice/Katrashova/lesson4/les 4.6.py b/Practice/Katrashova/lesson4/les 4.6.py new file mode 100644 index 0000000..7913b92 --- /dev/null +++ b/Practice/Katrashova/lesson4/les 4.6.py @@ -0,0 +1,23 @@ +def find_max(a, b): + if a > b: + return a + elif a < b: + return b + else: + print("Числа равны") +x = int(input("Введите число a: ")) +y = int(input("Введите число b: ")) +res = find_max(x, y) +print(f"Большее число: {res}") + + +def print_max(a, b): + if a > b: + print(a) + elif a < b: + print(b) + else: + print("Числа равны") +x = int(input("Введите число a: ")) +y = int(input("Введите число b: ")) +print_max(x, y) From 6af927c7f391bd0f670da9c6352dd2fae811826c Mon Sep 17 00:00:00 2001 From: Ksenia Date: Wed, 5 Oct 2022 09:46:46 +0300 Subject: [PATCH 04/17] 4.8 --- Practice/Katrashova/lesson4/les4.8.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Practice/Katrashova/lesson4/les4.8.py diff --git a/Practice/Katrashova/lesson4/les4.8.py b/Practice/Katrashova/lesson4/les4.8.py new file mode 100644 index 0000000..76d2fe7 --- /dev/null +++ b/Practice/Katrashova/lesson4/les4.8.py @@ -0,0 +1,26 @@ +import random + +print("Давай сыграем в камень, ножницы, бумага") + +while True: + y = input("Твой выбор - камень, ножницы, бумага: ") + x = ("камень", "ножницы", "бумага") + comp = random.choice(x) + print(f"Вы выбрали {y}, компьютер выбрал {comp}.") + if y == comp: + print("Ничья!") + elif y == "камень": + if comp == "ножницы": + print("Ты победил!") + else: + print("Ты проиграл.") + elif y == "бумага": + if comp == "камень": + print("Ты победил!") + else: + print("Ты проиграл.") + elif y == "ножницы": + if comp == "бумага": + print("Ты победил!") + else: + print("Ты проиграл.") \ No newline at end of file From 7c630ceedaaa0308259d62be32400450974cb797 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Sat, 8 Oct 2022 12:51:23 +0300 Subject: [PATCH 05/17] 4.7 --- Practice/Katrashova/lesson4/les4.7.py | 11 +++++++++++ Practice/Katrashova/lesson4/les4.8.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 Practice/Katrashova/lesson4/les4.7.py diff --git a/Practice/Katrashova/lesson4/les4.7.py b/Practice/Katrashova/lesson4/les4.7.py new file mode 100644 index 0000000..b2df8ca --- /dev/null +++ b/Practice/Katrashova/lesson4/les4.7.py @@ -0,0 +1,11 @@ +def my_decor(func): + def wrapper(): + print("===========") + func() + print("===========") + return wrapper + +def my_func(): + print("Тут основная функция") +my = my_decor(my_func) +my() \ No newline at end of file diff --git a/Practice/Katrashova/lesson4/les4.8.py b/Practice/Katrashova/lesson4/les4.8.py index 76d2fe7..3801772 100644 --- a/Practice/Katrashova/lesson4/les4.8.py +++ b/Practice/Katrashova/lesson4/les4.8.py @@ -1,10 +1,10 @@ import random print("Давай сыграем в камень, ножницы, бумага") +x = ("камень", "ножницы", "бумага") while True: y = input("Твой выбор - камень, ножницы, бумага: ") - x = ("камень", "ножницы", "бумага") comp = random.choice(x) print(f"Вы выбрали {y}, компьютер выбрал {comp}.") if y == comp: From 1d9d45699fa27db67481bdbb31872537e4a7175c Mon Sep 17 00:00:00 2001 From: Ksenia Date: Sun, 9 Oct 2022 17:01:23 +0300 Subject: [PATCH 06/17] 5.1 --- Practice/esafonova/task5.1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Practice/esafonova/task5.1.py b/Practice/esafonova/task5.1.py index 2ad8904..2e3e74c 100644 --- a/Practice/esafonova/task5.1.py +++ b/Practice/esafonova/task5.1.py @@ -8,6 +8,6 @@ def sort(arr): arr[m], arr[i] = arr[i], arr[m] return arr -arr = [6,3,24,26,3,7] + res = sort(arr) print(res) \ No newline at end of file From e3b3eabcdebed3f6d17e459c01299a6f9a6df5f7 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Sun, 9 Oct 2022 17:28:26 +0300 Subject: [PATCH 07/17] 5.1 and 5.2 --- Practice/Katrashova/lesson5/5.1.py | 12 ++++++++++++ Practice/Katrashova/lesson5/5.2.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 Practice/Katrashova/lesson5/5.1.py create mode 100644 Practice/Katrashova/lesson5/5.2.py diff --git a/Practice/Katrashova/lesson5/5.1.py b/Practice/Katrashova/lesson5/5.1.py new file mode 100644 index 0000000..a8f31ee --- /dev/null +++ b/Practice/Katrashova/lesson5/5.1.py @@ -0,0 +1,12 @@ +array = [0, 3, 24, 2, 3, 7] + +def arr_sort(arr): + for i in range(len(arr)): + min = i + for j in range(i + 1, len(arr)): + if arr[j] < arr[min]: + min = j + arr[i], arr[min] = arr[min], arr[i] + +arr_sort(array) +print(array) \ No newline at end of file diff --git a/Practice/Katrashova/lesson5/5.2.py b/Practice/Katrashova/lesson5/5.2.py new file mode 100644 index 0000000..7fb44dc --- /dev/null +++ b/Practice/Katrashova/lesson5/5.2.py @@ -0,0 +1,12 @@ +def fun(my_list): + new_set = set() + for i in range(len(my_list)): + if my_list[i] in new_set: + print(f'Первый повторившийся символ: {my_list[i]} ') + break + else: + new_set.add(my_list[i]) + + +lst = [2, 3, 4, 5, 3, 2] +fun(lst) \ No newline at end of file From 3e2aa9b657bc3ed7dcfa6e2d8a668bcea8ad5a6a Mon Sep 17 00:00:00 2001 From: Ksenia Date: Wed, 12 Oct 2022 11:51:53 +0300 Subject: [PATCH 08/17] =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=205=20=D0=BB=D0=B5=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/Katrashova/les4.5.py | 23 ----------------------- Practice/Katrashova/lesson5/5.3.py | 7 +++++++ Practice/Katrashova/lesson5/5.4.py | 27 +++++++++++++++++++++++++++ Practice/Katrashova/lesson5/5.5.py | 10 ++++++++++ Practice/Katrashova/lesson5/text.txt | 3 +++ 5 files changed, 47 insertions(+), 23 deletions(-) delete mode 100644 Practice/Katrashova/les4.5.py create mode 100644 Practice/Katrashova/lesson5/5.3.py create mode 100644 Practice/Katrashova/lesson5/5.4.py create mode 100644 Practice/Katrashova/lesson5/5.5.py create mode 100644 Practice/Katrashova/lesson5/text.txt diff --git a/Practice/Katrashova/les4.5.py b/Practice/Katrashova/les4.5.py deleted file mode 100644 index e9a57a1..0000000 --- a/Practice/Katrashova/les4.5.py +++ /dev/null @@ -1,23 +0,0 @@ -import random - -a = int(input("Введите начало диапазона: ")) -b = int(input("Введите конец диапазона: ")) -print("Число загадано в указанном диапазоне") -c = random.randint(a, b) - - -while True: - x = input("Попробуй отгадать моё число ") - if not x.isdecimal(): - print("Введено не число") - continue - x = int(x) - if x < c: - print("Введённое число меньше загаданного.") - elif x > c: - print("Введённое число больше загаданного.") - else: - print("Поздравляю, Вы угадали!") - break - - diff --git a/Practice/Katrashova/lesson5/5.3.py b/Practice/Katrashova/lesson5/5.3.py new file mode 100644 index 0000000..94061f0 --- /dev/null +++ b/Practice/Katrashova/lesson5/5.3.py @@ -0,0 +1,7 @@ +s ="Белеет парус одинокой \nв тумане моря голубом!.." +d = {"Белеет": "one", "парус": "two", "моря": "three"} + +print(f"До:\n{s}") +for i, value in d.items(): + s = s.replace(i, value) +print(f"После:\n{s}") \ No newline at end of file diff --git a/Practice/Katrashova/lesson5/5.4.py b/Practice/Katrashova/lesson5/5.4.py new file mode 100644 index 0000000..28623c2 --- /dev/null +++ b/Practice/Katrashova/lesson5/5.4.py @@ -0,0 +1,27 @@ +def search(ls, a): + ind = set() + for i in range(len(ls)): + for m in range(len(ls[i])): + if a == ls[i][m]: + ind.add(m) + ind = list(ind) + return ind + + +def delete(my_lst, lst_to_remove): + for i in range(len(my_lst)): + for n in reversed(lst_to_remove): + del my_lst[i][n] + return my_lst + + +lst = [ + [1, 2, 3, 4, 5, 6, 7], + [1, 1, 1, 2, 3, 4, 4], + [2, 2, 1, 3, 3, 5, 6] +] + +d = int(input("Ведите цифру для удаления стобцов( от 1 до 7): ")) +res = search(lst, d) +res2 = delete(lst, res) +print(f"Удалил: {res2}") \ No newline at end of file diff --git a/Practice/Katrashova/lesson5/5.5.py b/Practice/Katrashova/lesson5/5.5.py new file mode 100644 index 0000000..2726b86 --- /dev/null +++ b/Practice/Katrashova/lesson5/5.5.py @@ -0,0 +1,10 @@ +with open("text.txt", "r") as fo: + reading = fo.read() +my_choice = input("Что заменить? 1 - табуляция на пробелы, 2 - пробелы на табуляцию \n") + +with open("text.txt", "w") as fw: + if my_choice == "1": + fw.write(reading.replace("\t", " ")) + elif my_choice == "2": + fw.write(reading.replace(" ", "\t")) +print("Файл изменен") \ No newline at end of file diff --git a/Practice/Katrashova/lesson5/text.txt b/Practice/Katrashova/lesson5/text.txt new file mode 100644 index 0000000..e99060b --- /dev/null +++ b/Practice/Katrashova/lesson5/text.txt @@ -0,0 +1,3 @@ +There are different kinds of animals on our planet, and all of them are very important for it. +For example, everybody knows that the sharks are dangerous for people, but they are useful for cleaning seawater. +There are two types of animals: domestic (or pets) and wild. \ No newline at end of file From 97d7437cb6bc18018005cddef98f32edbc602e65 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Thu, 13 Oct 2022 12:21:45 +0300 Subject: [PATCH 09/17] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/Katrashova/lesson5/5.1.py | 13 ++++++---- Practice/Katrashova/lesson6/6.1.py | 23 +++++++++++++++++ Practice/Katrashova/lesson6/6.2.py | 41 ++++++++++++++++++++++++++++++ Practice/Katrashova/lesson6/6.3.py | 33 ++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 Practice/Katrashova/lesson6/6.1.py create mode 100644 Practice/Katrashova/lesson6/6.2.py create mode 100644 Practice/Katrashova/lesson6/6.3.py diff --git a/Practice/Katrashova/lesson5/5.1.py b/Practice/Katrashova/lesson5/5.1.py index a8f31ee..a2cc6f8 100644 --- a/Practice/Katrashova/lesson5/5.1.py +++ b/Practice/Katrashova/lesson5/5.1.py @@ -1,12 +1,15 @@ -array = [0, 3, 24, 2, 3, 7] def arr_sort(arr): for i in range(len(arr)): - min = i + m = i for j in range(i + 1, len(arr)): - if arr[j] < arr[min]: - min = j - arr[i], arr[min] = arr[min], arr[i] + if arr[j] < arr[m]: + m = j + arr[i], arr[m] = arr[m], arr[i] + if i != m: + arr[i], arr[m] = arr[m], arr[i] + +array = [0, 3, 24, 2, 3, 7] arr_sort(array) print(array) \ No newline at end of file diff --git a/Practice/Katrashova/lesson6/6.1.py b/Practice/Katrashova/lesson6/6.1.py new file mode 100644 index 0000000..7b6397e --- /dev/null +++ b/Practice/Katrashova/lesson6/6.1.py @@ -0,0 +1,23 @@ +class Tank(): + def __init__(self, name, crew, weight): + self.name = name + self.crew = crew + self.weight = weight + + def show(self): + print(f"Танк {self.name} экипажем {self.crew} человек(а), и массой {self.weight}") + + def __lt__(self, other): + if self.weight > other.weight: + print(f'У Игрока {self.name} больше шансов') + elif self.weight == other.weight: + print('Шансы равны') + else: + print(f'У Игрока {self.name} меньше шансов') + + +player1 = Tank('T-80', 3, 40) +player2 = Tank('T-34', 4, 30) +lst = [player1, player2] +for i in lst: + i.show() diff --git a/Practice/Katrashova/lesson6/6.2.py b/Practice/Katrashova/lesson6/6.2.py new file mode 100644 index 0000000..20c8052 --- /dev/null +++ b/Practice/Katrashova/lesson6/6.2.py @@ -0,0 +1,41 @@ +class Duck: + color = "белый" + + def __init__(self, name, weight): + self.name = name + self.weight = weight + + @staticmethod + def crack(): + print("Сrack") + + @classmethod + def color_duck(cls): + print(f"Цвет утки {cls.color}") + + def __repr__(self): + return f"Имя утки: {self.name}, вес {self.weight} кг" + + def __lt__(self, other): + if self.weight < other.weight: + return f"Утка {other.name} тяжелее" + else: + return f"Утка {self.name} тяжелее" + + def __ne__(self, other): + return self.weight != other.weight + + def __add__(self, other): + return self.weight + other.weight + + +duck1 = Duck("Катя", 4) +duck2 = Duck("Вика", 5) + +duck1.crack() +duck2.color_duck() +print(duck1) +print(duck2) +print(duck1 < duck2) +print(duck1 != duck2) +print(f"Общий вес уток {duck1 + duck2} кг") diff --git a/Practice/Katrashova/lesson6/6.3.py b/Practice/Katrashova/lesson6/6.3.py new file mode 100644 index 0000000..4a7b99f --- /dev/null +++ b/Practice/Katrashova/lesson6/6.3.py @@ -0,0 +1,33 @@ +import tempfile +import os + + +class WrapStrToFile: + def __init__(self): + self._filepath = tempfile.mktemp() + + @property + def content(self): + try: + with open(self._filepath, 'r') as f: + return f.read() + except Exception: + return 'Файл еще не существует' + + @content.setter + def content(self, value): + with open(self._filepath, 'w') as f: + f.write(value) + + @content.deleter + def content(self): + os.remove(self._filepath) + + +a = WrapStrToFile() +print(a.content) # Output: File doesn't exist +a.content = 'test str' +print(a.content) # Output: test_str +a.content = 'text 2' +print(a.content) # Output: text 2 +del a.content # после этого файла не существует From 65c81bc90a7f605065aa0147f83291af2d24b188 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Sat, 15 Oct 2022 16:13:10 +0300 Subject: [PATCH 10/17] =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D1=8F=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/Katrashova/lesson5/5.1.py | 1 - Practice/Katrashova/lesson7/les7.1.py | 9 +++++++++ Practice/Katrashova/lesson7/les7.2.py | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Practice/Katrashova/lesson7/les7.1.py create mode 100644 Practice/Katrashova/lesson7/les7.2.py diff --git a/Practice/Katrashova/lesson5/5.1.py b/Practice/Katrashova/lesson5/5.1.py index a2cc6f8..3d1a75d 100644 --- a/Practice/Katrashova/lesson5/5.1.py +++ b/Practice/Katrashova/lesson5/5.1.py @@ -5,7 +5,6 @@ def arr_sort(arr): for j in range(i + 1, len(arr)): if arr[j] < arr[m]: m = j - arr[i], arr[m] = arr[m], arr[i] if i != m: arr[i], arr[m] = arr[m], arr[i] diff --git a/Practice/Katrashova/lesson7/les7.1.py b/Practice/Katrashova/lesson7/les7.1.py new file mode 100644 index 0000000..aafb689 --- /dev/null +++ b/Practice/Katrashova/lesson7/les7.1.py @@ -0,0 +1,9 @@ +class Man: + def __init__(self, name): + self.name = name + + def solve_task(self): + print("I'm not ready yet") + +man = Man('Альберт') +man.solve_task() \ No newline at end of file diff --git a/Practice/Katrashova/lesson7/les7.2.py b/Practice/Katrashova/lesson7/les7.2.py new file mode 100644 index 0000000..7b52415 --- /dev/null +++ b/Practice/Katrashova/lesson7/les7.2.py @@ -0,0 +1,21 @@ +import time +import random + +class Man: + + def __init__(self, name): + self.name = name + def solve_task(self): + print("I'm not ready yet") + +class Pupil(Man): + def solve_task(self): + delay = random.randint(3, 6) + time.sleep(delay) + super().solve_task() + + +man = Man("Альберт") +pupil = Pupil("Арнольд") +man.solve_task() +pupil.solve_task() \ No newline at end of file From c77920435975b9534ab4fdb2ab2135bc3c5dc891 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Tue, 18 Oct 2022 20:39:23 +0300 Subject: [PATCH 11/17] =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D1=8F=208?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/Katrashova/lesson8/8.1.py | 30 ++++++++++++++++++++++++++++ Practice/Katrashova/lesson8/8.2.py | 8 ++++++++ Practice/Katrashova/lesson8/8.3.py | 17 ++++++++++++++++ Practice/Katrashova/lesson8/8.4.py | 18 +++++++++++++++++ Practice/Katrashova/lesson8/text.txt | 4 ++++ 5 files changed, 77 insertions(+) create mode 100644 Practice/Katrashova/lesson8/8.1.py create mode 100644 Practice/Katrashova/lesson8/8.2.py create mode 100644 Practice/Katrashova/lesson8/8.3.py create mode 100644 Practice/Katrashova/lesson8/8.4.py create mode 100644 Practice/Katrashova/lesson8/text.txt diff --git a/Practice/Katrashova/lesson8/8.1.py b/Practice/Katrashova/lesson8/8.1.py new file mode 100644 index 0000000..44578bb --- /dev/null +++ b/Practice/Katrashova/lesson8/8.1.py @@ -0,0 +1,30 @@ +class Iter: + + def __init__(self, text, my_sim): + self.text = text + self.my_sim = my_sim + + def __iter__(self): + return self + + def __next__(self): + my_str = ' ' + new_str = '' + while my_str != '': + my_str = self.text.read(1) + if my_str == self.my_sim: + break + else: + new_str += my_str + + if new_str != '': + return new_str + else: + raise StopIteration + + + + +with open('text.txt', 'r') as f: + for i in Iter(f, '§'): + print(i) \ No newline at end of file diff --git a/Practice/Katrashova/lesson8/8.2.py b/Practice/Katrashova/lesson8/8.2.py new file mode 100644 index 0000000..ee0bfc4 --- /dev/null +++ b/Practice/Katrashova/lesson8/8.2.py @@ -0,0 +1,8 @@ +def my_gen(file): + with open(file, 'r', encoding='utf8') as f: + for s in f: + yield s + + +for i in my_gen('text.txt'): + print(i) \ No newline at end of file diff --git a/Practice/Katrashova/lesson8/8.3.py b/Practice/Katrashova/lesson8/8.3.py new file mode 100644 index 0000000..2a16383 --- /dev/null +++ b/Practice/Katrashova/lesson8/8.3.py @@ -0,0 +1,17 @@ +import time + +class Wait: + def __init__(self): + self.begint = 0 + + def __enter__(self): + self.begint = time.time() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + print(f"Around time: {time.time() - self.begint} seconds") + +with Wait(): + arr = [] + for i in range(1, 10000000): + arr.append(i**2) \ No newline at end of file diff --git a/Practice/Katrashova/lesson8/8.4.py b/Practice/Katrashova/lesson8/8.4.py new file mode 100644 index 0000000..d5ebf09 --- /dev/null +++ b/Practice/Katrashova/lesson8/8.4.py @@ -0,0 +1,18 @@ +import itertools + + +def arr(num1, num2, num3): + joint = list(itertools.chain(num1, num2, num3)) + return joint + +def less(lst): + filtered = list(itertools.filterfalse(lambda x: len(x) != 5, lst)) + return filtered + +def key(string, r): + passwords = list(itertools.combinations(string, r)) + return passwords + +print(arr([1, 2, 3], [4, 5], [6, 7])) +print(less(['hello', 'i', 'write', 'cool', 'code'])) +print(key('password', 4)) \ No newline at end of file diff --git a/Practice/Katrashova/lesson8/text.txt b/Practice/Katrashova/lesson8/text.txt new file mode 100644 index 0000000..497e44f --- /dev/null +++ b/Practice/Katrashova/lesson8/text.txt @@ -0,0 +1,4 @@ +§ It goes without saying, books are our teachers and friends. They teach us to be kind, clever, polite, hardworking, friendly. +§ Books help us to learn more about nature, the world around us and many other interesting things.There are a lot of books on history, about animals, travellers, children, school and so on. +§ Children like to read adventure and magic books, science fiction and detective stories. +§ They enjoy stories, short stories, novels, fairy-tales, fables and poems. \ No newline at end of file From dfc53067bb70d7ce65bc7c040184eaeed513f665 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Fri, 28 Oct 2022 14:23:33 +0300 Subject: [PATCH 12/17] =?UTF-8?q?func=20=D0=B2=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=BD=D1=83=D1=8E=20=D0=B8=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/Katrashova/lesson4/les4.7.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Practice/Katrashova/lesson4/les4.7.py b/Practice/Katrashova/lesson4/les4.7.py index b2df8ca..a763ffa 100644 --- a/Practice/Katrashova/lesson4/les4.7.py +++ b/Practice/Katrashova/lesson4/les4.7.py @@ -1,8 +1,9 @@ def my_decor(func): def wrapper(): print("===========") - func() + res = func() print("===========") + return res return wrapper def my_func(): From 7dc211ce6834d8ca02b15cc4f5ade4d4a25b3e09 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Sun, 30 Oct 2022 11:35:52 +0300 Subject: [PATCH 13/17] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/Katrashova/lesson5/5.2.py | 2 +- Practice/ShulginaN/Lec_5/task_5.py | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Practice/Katrashova/lesson5/5.2.py b/Practice/Katrashova/lesson5/5.2.py index 7fb44dc..eef559e 100644 --- a/Practice/Katrashova/lesson5/5.2.py +++ b/Practice/Katrashova/lesson5/5.2.py @@ -1,6 +1,6 @@ def fun(my_list): new_set = set() - for i in range(len(my_list)): + for i in my_list: if my_list[i] in new_set: print(f'Первый повторившийся символ: {my_list[i]} ') break diff --git a/Practice/ShulginaN/Lec_5/task_5.py b/Practice/ShulginaN/Lec_5/task_5.py index 2d780a6..8314f4d 100644 --- a/Practice/ShulginaN/Lec_5/task_5.py +++ b/Practice/ShulginaN/Lec_5/task_5.py @@ -1,8 +1,3 @@ -# Реализовать функциональность, которая бы “сворачивала” и “разворачивала” символы табуляции в файле. -# То есть, на вход передается файл, необходимо заменить все символы табуляции на четыре пробела, -# либо же заменить все комбинации из четырех символов пробела на символ табуляции -# (в зависимости от опции указанной пользователем). - with open("my_file.txt", "r") as fo: reading = fo.read() From 4e491eb4825c0f351970086253b26587cbc1be26 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Sun, 30 Oct 2022 11:37:55 +0300 Subject: [PATCH 14/17] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/Katrashova/lesson5/5.2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Practice/Katrashova/lesson5/5.2.py b/Practice/Katrashova/lesson5/5.2.py index eef559e..46d7c02 100644 --- a/Practice/Katrashova/lesson5/5.2.py +++ b/Practice/Katrashova/lesson5/5.2.py @@ -1,7 +1,7 @@ def fun(my_list): new_set = set() for i in my_list: - if my_list[i] in new_set: + if i in new_set: print(f'Первый повторившийся символ: {my_list[i]} ') break else: From 5d191cf4bcd2e334a97170d7ae85277328127007 Mon Sep 17 00:00:00 2001 From: KseniaKatrashova <112473264+KseniaKatrashova@users.noreply.github.com> Date: Mon, 31 Oct 2022 12:36:30 +0300 Subject: [PATCH 15/17] Delete task_5.py --- Practice/ShulginaN/Lec_5/task_5.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 Practice/ShulginaN/Lec_5/task_5.py diff --git a/Practice/ShulginaN/Lec_5/task_5.py b/Practice/ShulginaN/Lec_5/task_5.py deleted file mode 100644 index 8314f4d..0000000 --- a/Practice/ShulginaN/Lec_5/task_5.py +++ /dev/null @@ -1,12 +0,0 @@ - -with open("my_file.txt", "r") as fo: - reading = fo.read() -my_choice = input("Что необходимо заменить? 1 - табуляция на пробелы, 2 - пробелы на табуляцию \n") - -with open("my_file.txt", "w") as fw: - if my_choice == "1": - fw.write(reading.replace("\t", " ")) - elif my_choice == "2": - fw.write(reading.replace(" ", "\t")) -print("Заменил,см. my_file") - From f7af689ad94662de516ba06ab773003a77d48bc2 Mon Sep 17 00:00:00 2001 From: KseniaKatrashova <112473264+KseniaKatrashova@users.noreply.github.com> Date: Mon, 31 Oct 2022 13:25:47 +0300 Subject: [PATCH 16/17] Delete task5.1.py --- Practice/esafonova/task5.1.py | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 Practice/esafonova/task5.1.py diff --git a/Practice/esafonova/task5.1.py b/Practice/esafonova/task5.1.py deleted file mode 100644 index 2ad8904..0000000 --- a/Practice/esafonova/task5.1.py +++ /dev/null @@ -1,13 +0,0 @@ -def sort(arr): - for i in range(len(arr)): - m = i - for j in range(i + 1, len(arr)): - if arr[j] < arr[m]: - m = j - if m != i: - arr[m], arr[i] = arr[i], arr[m] - return arr - -arr = [6,3,24,26,3,7] -res = sort(arr) -print(res) \ No newline at end of file From 63edb1f17ba6cd1914f82dab5a84a429dfcd1d9d Mon Sep 17 00:00:00 2001 From: KseniaKatrashova <112473264+KseniaKatrashova@users.noreply.github.com> Date: Mon, 31 Oct 2022 13:26:02 +0300 Subject: [PATCH 17/17] Delete Task 03.py --- Practice/RybnikovS/Lec 04/Task 03.py | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 Practice/RybnikovS/Lec 04/Task 03.py diff --git a/Practice/RybnikovS/Lec 04/Task 03.py b/Practice/RybnikovS/Lec 04/Task 03.py deleted file mode 100644 index cb28013..0000000 --- a/Practice/RybnikovS/Lec 04/Task 03.py +++ /dev/null @@ -1,11 +0,0 @@ - s = "" -while True: - x = input("Введите символ: ") - if x.upper() == "STOP": - print("Программа завершена") - break - elif not x.isdecimal(): - print("Некорректный ввод") - else: - s += x - print(f"Ваше число {s}")