diff --git a/Practice/MoiseevD/lesson_4_1.py b/Practice/MoiseevD/lesson_4_1.py new file mode 100644 index 0000000..4c42fc3 --- /dev/null +++ b/Practice/MoiseevD/lesson_4_1.py @@ -0,0 +1,11 @@ +i = 0 +while i < 100: + i += 1 + if i % 15 == 0: + print('FizzBizz') + elif i % 5 == 0: + print('Bizz') + elif i % 3 == 0: + print('Fizz') + else: + print(i) \ No newline at end of file diff --git a/Practice/MoiseevD/lesson_4_2.py b/Practice/MoiseevD/lesson_4_2.py new file mode 100644 index 0000000..8b89a2b --- /dev/null +++ b/Practice/MoiseevD/lesson_4_2.py @@ -0,0 +1,5 @@ +s = input('Введите пятизначное число: ') +i = 0 +while i < len(s): + i += 1 + print(f'{i} Цифра равна: {s[i-1]}') \ No newline at end of file diff --git a/Practice/MoiseevD/lesson_4_3.py b/Practice/MoiseevD/lesson_4_3.py new file mode 100644 index 0000000..eef8361 --- /dev/null +++ b/Practice/MoiseevD/lesson_4_3.py @@ -0,0 +1,14 @@ +str_num = "" + +while True: + s = input('Введите число, для выхода введите "stop" : ') + + if s.lower() == 'stop': + break + + if not s.isdecimal(): + print('--Введите только число--') + continue + + str_num += s +print(str_num) diff --git a/Practice/MoiseevD/lesson_4_4.py b/Practice/MoiseevD/lesson_4_4.py new file mode 100644 index 0000000..814a134 --- /dev/null +++ b/Practice/MoiseevD/lesson_4_4.py @@ -0,0 +1,14 @@ +import random + + +s = ('Ты сам-то понял, что написал?', 'Аргументируй', 'И?') + +while True: + question = input('Задайте вопрос: ') + + if question.lower() == 'хватит': + print('---Выход из программы---') + break + else: + answers = random.choice(s) + print(answers) diff --git a/Practice/MoiseevD/lesson_4_5.py b/Practice/MoiseevD/lesson_4_5.py new file mode 100644 index 0000000..47c4e33 --- /dev/null +++ b/Practice/MoiseevD/lesson_4_5.py @@ -0,0 +1,20 @@ +import random + + +s = int(input('Введите нижний диапазон: ')) +s1 = int(input('Введите верхний диапазон: ')) +num = random.randint(s, s1) + +while True: + guess_str = input('Угадайте число: ') + if not guess_str.isdecimal(): + print('---Завершение---') + break + guess = int(guess_str) + if guess == num: + print('---Вы угадали---') + break + elif guess < num: + print(' Ваше число меньше ') + elif guess > num: + print(' Ваше число больше ') diff --git a/Practice/MoiseevD/lesson_4_6.py b/Practice/MoiseevD/lesson_4_6.py new file mode 100644 index 0000000..ac4793c --- /dev/null +++ b/Practice/MoiseevD/lesson_4_6.py @@ -0,0 +1,13 @@ +def max_item(a, b): + print(max(a, b)) + + +def max_ret(a, b): + return max(a, b) + + +high = int(input('Введите первое число: ')) +low = int(input('Введите второе число: ')) +max_item(high, low) +b = max_ret(high, low) +print(b) \ No newline at end of file diff --git a/Practice/MoiseevD/lesson_4_7.py b/Practice/MoiseevD/lesson_4_7.py new file mode 100644 index 0000000..d589a9f --- /dev/null +++ b/Practice/MoiseevD/lesson_4_7.py @@ -0,0 +1,16 @@ +def decor_start(start): + def decor_finish(*args, **kwargs): + print("=====1======") + res = start(*args, **kwargs) + print("=====2======") + return res + return decor_finish + + +@decor_start +def start_finish(start): + print(start) + + +start_finish('=================') + diff --git a/Practice/MoiseevD/lesson_4_8.py b/Practice/MoiseevD/lesson_4_8.py new file mode 100644 index 0000000..c8be3eb --- /dev/null +++ b/Practice/MoiseevD/lesson_4_8.py @@ -0,0 +1,32 @@ +import random + + +game_list = ("камень", "ножницы", "бумага") + +while True: + game = random.choice(game_list) + s = input('Введите слово "КАМЕНЬ", "НОЖНИЦЫ", или "БУМАГА": ') + s = s.lower() + if s == 'камень': + if game == game_list[0]: + print(f'---{game}---\n Ничья') + elif game == game_list[1]: + print(f'---{game}---\n Вы выиграли') + else: + print(f'---{game}---\n Вы проиграли') + + elif s == 'ножницы': + if game == game_list[0]: + print(f'---{game}---\n Вы проиграли') + elif game == game_list[1]: + print(f'---{game}---\n Ничья') + else: + print(f'---{game}---\n Вы выиграли') + + elif s.lower() == 'бумага': + if game == game_list[0]: + print(f'---{game}---\n Вы выиграли') + elif game == game_list[1]: + print(f'---{game}---\n Вы проиграли') + else: + print(f'---{game}---\n Ничья') \ No newline at end of file diff --git a/Practice/MoiseevD/lesson_5_1.py b/Practice/MoiseevD/lesson_5_1.py new file mode 100644 index 0000000..4073ed1 --- /dev/null +++ b/Practice/MoiseevD/lesson_5_1.py @@ -0,0 +1,25 @@ +def current_index(arr, idx): + idx_min = idx + i = idx + # while i < len(arr): + # if arr[i] < arr[idx_min]: + # idx_min = i + # i += 1 + for i in range(idx, len(arr)): + if arr[i] < arr[idx_min]: + idx_min = i + i += 1 + return idx_min + + +def min_element(elm): + for i in range(len(elm)): + cur_idx = current_index(elm, i) + if cur_idx != i: + elm[cur_idx], elm[i] = elm[i], elm[cur_idx] + return elm + + +a = [0, 3, 24, 2, 3, 7] +res = min_element(a) +print(res) diff --git a/Practice/MoiseevD/lesson_6_1.py b/Practice/MoiseevD/lesson_6_1.py new file mode 100644 index 0000000..57643a5 --- /dev/null +++ b/Practice/MoiseevD/lesson_6_1.py @@ -0,0 +1,31 @@ +class Tank: + def __init__(self, power, model): + self.power = power + self.model = model + +class T34(Tank): + def shoot(self): + print(self.model, ' - Бах') + +class Tiger(Tank): + def shoot(self): + print(self.model, ' - Ба-бах') + +class Abrams(Tank): + def shoot(self): + print(self.model, ' - Ба-ба-бах') + +while True: + t = input('Введите одну из мощностей выстрела: 30 - 80 - 90 ') + if t.lower() == 'stop': + print('Выход из программы') + break + elif t == '30': + tnk1 = T34(30, 'T34') + tnk1.shoot() + elif t == '80': + tnk2 = Tiger(80, 'Tiger') + tnk2.shoot() + elif t == '90': + tnk3 = Abrams(90, 'Abrams') + tnk3.shoot() diff --git a/Practice/MoiseevD/lesson_6_2.py b/Practice/MoiseevD/lesson_6_2.py new file mode 100644 index 0000000..40c1f73 --- /dev/null +++ b/Practice/MoiseevD/lesson_6_2.py @@ -0,0 +1,44 @@ +class Duck: + def __init__(self, name, weight, collor): + self._name = name + self._weight = weight + self._collor = collor + + def name_weight(self): + print('Имя:', self._name, ' Вес:', self._weight, 'кг') + + def __repr__(self): + return f'class Duck: name = {self._name} weight = {self._weight} collor = {self._collor}' + + def __lt__(self, other): + if self._weight < other._weight: + return other._name + else: + return self._name + + def __ne__(self, other): + return self._weight != other._weight + + def __add__(self, other): + return self._weight + other._weight + + @classmethod + def collor_duck(cls, collor): + print(cls, collor) + + @staticmethod + def crack_duck(): + print('Crack') + + +p = Duck('Гага', 4, 'белый',) +p1 = Duck('КряКря', 7, 'черный',) + +p.crack_duck() +p.collor_duck('черный') +p.name_weight() +print(repr(p)) +print(repr(p1)) +print('Самая тяжелая утка: ', p < p1) +print('Вес уток не равен: ', p != p1) +print('Общий вес уток: ', p + p1) diff --git a/Practice/MoiseevD/lesson_7_1.py b/Practice/MoiseevD/lesson_7_1.py new file mode 100644 index 0000000..ebf353b --- /dev/null +++ b/Practice/MoiseevD/lesson_7_1.py @@ -0,0 +1,10 @@ +class Man: + def __init__(self, name): + self._name = name + + def solve_task(self): + print("I'm not ready yet") + + +res = Man('Дмитрий') +res.solve_task() \ No newline at end of file diff --git a/Practice/MoiseevD/lesson_7_2.py b/Practice/MoiseevD/lesson_7_2.py new file mode 100644 index 0000000..1091f1b --- /dev/null +++ b/Practice/MoiseevD/lesson_7_2.py @@ -0,0 +1,21 @@ +import time +import random + + +class Pupil: + def __init__(self, name): + self._name = name + + def solve_task(self): + print("I'm not ready yet") + + +class Tim(Pupil): + def solve_task(self): + n = random.randint(3, 6) + time.sleep(n) + super().solve_task() + + +res = Tim('Дмитрий') +res.solve_task() \ No newline at end of file diff --git a/Practice/MoiseevD/lesson_7_3.py b/Practice/MoiseevD/lesson_7_3.py new file mode 100644 index 0000000..409fcdf --- /dev/null +++ b/Practice/MoiseevD/lesson_7_3.py @@ -0,0 +1,48 @@ +class Bank: + def __init__(self, cash): + self._cash = cash + + +class Bankomat1(Bank): + def input_output(self): + while True: + inp = input('Внести деньги - введите "1". Для снятия - "2" ') + if inp.lower() == '1': + inp = int(input('Положите купюры в лоток: ')) + self._cash += inp + elif inp.lower() == '2': + out = int(input('Введите требуемую сумму: ')) + if self._cash < out: + print('=== Не достаточно денег в банкомате ===') + continue + self._cash -= out + else: + print('----- Неправильный ввод.-----\n ' + 'Для выхода введите: EXIT \n' + 'Для продолжения операции введите любой знак: ') + stop = input('---- ') + if stop.lower() == 'exit': + print('Выход') + break + continue + print(f'Оставшаяся наличность в Bankomat1 : {self._cash}') + + +class Bankomat2(Bank): + def exchange(self): + print(f'Оставшаяся наличность в Bankomat2: {self._cash}') + + +class Bankomat3(Bank): + def transfer(self): + print(f'Оставшаяся наличность в Bankomat3: {self._cash}') + + +#lst = Bank(1000) +lst1 = Bankomat1(500) +lst2 = Bankomat2(1500) +lst3 = Bankomat3(3000) + +lst1.input_output() +lst2.exchange() +lst3.transfer() \ No newline at end of file diff --git a/Practice/MoiseevD/lesson_8_3.py b/Practice/MoiseevD/lesson_8_3.py new file mode 100644 index 0000000..5e2174c --- /dev/null +++ b/Practice/MoiseevD/lesson_8_3.py @@ -0,0 +1,19 @@ +import time + + +class timeManager: + + def __enter__(self): + self.t1 = time.time() + print(f'Запуск таймера в менеджере контекста {self.t1}') + + def __exit__(self, exc_type, exc_val, exc_tb): + self.t2 = time.time() - self.t1 + print('Остановка таймера менеджера контекста') + print(f'Время исполнения кода {self.t2}') + + +lst =range(2, 100000) +with timeManager(): + for i in lst: + print(i) diff --git a/Practice/MoiseevD/read_8_1.txt b/Practice/MoiseevD/read_8_1.txt new file mode 100644 index 0000000..c0b74e0 --- /dev/null +++ b/Practice/MoiseevD/read_8_1.txt @@ -0,0 +1 @@ + Реализовать итератор, который бы "читал" заданный текст по параграфам. &Символ параграфа задается отдельно. \ No newline at end of file diff --git a/Practice/MoiseevD/read_8_2.txt b/Practice/MoiseevD/read_8_2.txt new file mode 100644 index 0000000..b8adf60 --- /dev/null +++ b/Practice/MoiseevD/read_8_2.txt @@ -0,0 +1,3 @@ +Привет! +Добро пожаловать на Python. +Удачи в обучении! \ No newline at end of file