From b17e5ee409166cae77f43650dfc29b150a024a74 Mon Sep 17 00:00:00 2001 From: Bear346 <57682132+Bear346@users.noreply.github.com> Date: Tue, 27 Oct 2020 13:33:31 +0300 Subject: [PATCH 1/6] Create Lecture2.py --- Practice/MIsakichev/Lecture2.py | 89 +++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Practice/MIsakichev/Lecture2.py diff --git a/Practice/MIsakichev/Lecture2.py b/Practice/MIsakichev/Lecture2.py new file mode 100644 index 00000000..d71f7c06 --- /dev/null +++ b/Practice/MIsakichev/Lecture2.py @@ -0,0 +1,89 @@ +#Лекция ДВА +# first task +def biggestPrint(a,b): + if(a>b): + print(a) + else: print(b) +biggestPrint(2,4) +biggestPrint(15,11) + +#second task +def biggestReturn(a,b): + if(a>b): + return a + else:return b +result = biggestReturn(100,200) +result2=biggestReturn(1000,500) +print(result) +print(result2) + +#oop task GAME +class Characters: + def __init__(self,name,capability): + self.name=name, + self.capability=capability + @staticmethod + def gameStarted(): + print("Game started") + + def running(self,speed): + print(f'{self.name} is beginning running with speed {speed}') + return 'Running' + + def usingCapability(self): + print(f'{self.name}using capability {self.capability}') + return self.capability + + def pickUpItemForUpgrade(self): + print(f'{self.name}picked up item BonusSpeed') + return 'BonusSpeed' + + def pickUpItemForDowngrade(self): + print(f'{self.name}picked up item SlowSpeed') + return 'SlowSpeed' + + def UsingItem(self,item,speed,obj): + print(f"{self.name}using item on {obj}") + if item == 'BonusSpeed': + return speed + 10 + elif item=='SlowSpeed': + return speed - 20 + else : return 0 + + def flying(self,speed): + print(f'{self.name} is beginning flying with speed {speed} ') + return 'flying' + #воспроизвести в зависимости от действия анимацию + def chooseAnimation(self,anim): + if anim == 'Running': + print(f'{self.name} run animation starts') + if anim == 'flying': + print(f'{self.name} fly animation starts') + if anim == 'Shooting': + print(f'{self.name} shooting animation starts') + if anim == 'Attack from air': + print(f'{self.name} attack from air animation starts') + if anim == 'Attack with axe': + print(f'{self.name} attack with axe animation starts') + #Взять анимацию + def getAnim(self,anim): + return anim + + def getItem(self,item): + return item + +Characters.gameStarted() +human = Characters("Human","Shooting") +daemon = Characters("Demon","Attack from air") +ork=Characters("Ork","Attack with axe") + +human.chooseAnimation(human.getAnim(human.running(50))) +daemon.chooseAnimation(daemon.getAnim(daemon.flying(100))) +ork.chooseAnimation(ork.getAnim(ork.running(75))) +speedDown = daemon.UsingItem(daemon.getItem(daemon.pickUpItemForDowngrade()),50,'Human') +human.chooseAnimation(human.getAnim(human.running(speedDown))) +speedUp=human.UsingItem(human.getItem(human.pickUpItemForUpgrade()),speedDown,'Human') +human.chooseAnimation(human.getAnim(human.running(speedUp))) +human.chooseAnimation(human.getAnim(human.usingCapability())) +daemon.chooseAnimation(daemon.getAnim(daemon.usingCapability())) +ork.chooseAnimation(ork.getAnim(ork.usingCapability())) From 86651d6a43656235108ca17dc88ed887fd42df27 Mon Sep 17 00:00:00 2001 From: Bear346 <57682132+Bear346@users.noreply.github.com> Date: Tue, 27 Oct 2020 13:34:35 +0300 Subject: [PATCH 2/6] Create Lecture3_4.py --- Practice/MIsakichev/Lecture3_4.py | 90 +++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Practice/MIsakichev/Lecture3_4.py diff --git a/Practice/MIsakichev/Lecture3_4.py b/Practice/MIsakichev/Lecture3_4.py new file mode 100644 index 00000000..7788c23e --- /dev/null +++ b/Practice/MIsakichev/Lecture3_4.py @@ -0,0 +1,90 @@ +#Лекция 3-4 +#task one +def FizzBuzz(i): + if i % 15 == 0: + print("FizzBuzz") + elif i % 5 == 0: + print("Buzz") + elif i % 3 == 0: + print("Fizz") + else: print(i) + +for i in range(1,101): + FizzBuzz(i) + +#task two +def number(): + num = input('Enter the number') + j=0 + for i in num: + if(len(num) > 5): + print("Можно вводить только пятизначные цифры") + break + else: + j+=1 + print(f'{j} цифра равна {i}') +number() + +#task three +def selecting_sort(arr): + for i in range(len(arr) - 1): + k= i + j = i + 1 + while j < len(arr): + if arr[j] < arr[k]: + k = j + j += 1 + arr[i], arr[k] = arr[k], arr[i] + +arr = [0,3,24,2,3,7] +print('Before sorting') +print(arr) +selecting_sort(arr) +print('after sorting') +print(arr) + +#task four + +def str_deploy(str): + ch=' ' + if '\t' in str: + if ch in str: + str = str.replace(ch, '\t') + str = str.replace('\t',' ') + return str + +str1 = 'Privet\tmenya zovut Vasya\tI live in Moscow' +str3 = str_deploy(str1) +print(str1) + + +#task five +def templates(line): + dict = {'Goodbye':'Hello','hate':'Love'} + for key, v in dict.items(): + line = line.replace(key, v) + return line + +string = 'Goodbye I hate you ' +print(templates(string)) + +#task six +import numpy as np +def deleting_column(list): + k=0 + num = int(input('enter the number for deleting column consist of this number')) + for i in list: + for j in i: + if j == num: + list = np.delete(list,k,1) + else: + k+=1 + k=0 + return list +l =[[1,2,33,100], + [44,5,6,245], + [7,8,9,17]] +l = deleting_column(l) +print('Matrix after deleting') +print(l) + From a5d507ff5c5c5b6f50925d2e1b8c8dedd1d06e89 Mon Sep 17 00:00:00 2001 From: Bear346 <57682132+Bear346@users.noreply.github.com> Date: Tue, 27 Oct 2020 13:35:15 +0300 Subject: [PATCH 3/6] Create Lecture5.py --- Practice/MIsakichev/Lecture5.py | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Practice/MIsakichev/Lecture5.py diff --git a/Practice/MIsakichev/Lecture5.py b/Practice/MIsakichev/Lecture5.py new file mode 100644 index 00000000..4f4c59e5 --- /dev/null +++ b/Practice/MIsakichev/Lecture5.py @@ -0,0 +1,69 @@ +#ЛЕКЦИЯ ПЯТЬ +#task one +class Man: + def __init__(self,name): + self.name=name + + def solve_task(self): + print ("I'm not ready yet") +man = Man("Vasya") +man.solve_task() + +#task two +import time +import random + +class Pupil(Man): + def __init__(self,name): + super().__init__(name) + + def solve_task(self): + a = random.randint(3,6) + time.sleep(a) + print("I'm not ready yet") + +p = Pupil('Vasya') +p.solve_task() + +#task three +import tempfile +import os +class WrapStrToFile: + def __init__(self): + self.filepath = tempfile.mktemp() + + @property + def content(self): + try: + file = open(self.filepath, 'r') + string = file.read() + file.close() + return string + + except OSError: + return "File not found" + + @content.setter + def content(self, value): + try: + file = open(self.filepath, 'w') + file.write(value) + file.close() + except Exception as ex: + print("Unexpected error: {}".format(ex)) + + @content.deleter + def content(self): + try: + os.remove(self.filepath) + except Exception as ex: + print("Unexpected error: {}".format(ex)) + + +wstf = WrapStrToFile() +print(wstf.content) # Output: File doesn't exist +wstf.content = 'test str' +print(wstf.content) # Output: test_str +wstf.content = 'text 2' +print(wstf.content) # Output: text 2 +del wstf.content From 6ef404975aef20e86da06630588cb2de9692c34a Mon Sep 17 00:00:00 2001 From: Bear346 <57682132+Bear346@users.noreply.github.com> Date: Tue, 27 Oct 2020 13:35:44 +0300 Subject: [PATCH 4/6] Create Lecture6.py --- Practice/MIsakichev/Lecture6.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Practice/MIsakichev/Lecture6.py diff --git a/Practice/MIsakichev/Lecture6.py b/Practice/MIsakichev/Lecture6.py new file mode 100644 index 00000000..2eeb2e2a --- /dev/null +++ b/Practice/MIsakichev/Lecture6.py @@ -0,0 +1,29 @@ +#ЛЕКЦИЯ ШЕСТЬ +#task three +import time +class Calculate_time: + def __init__(self): + self.start = 0 + + def __enter__(self): + self.start = time.time() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + print(f"Time of execution is = {time.time() - self.start}") + + +with Calculate_time(): + buffer = [] + for k in range(1, 10000000): + buffer.append(k**2) + +#task four +import itertools as it +def list_transform(arr): + list(it.chain([1, 2, 3], [4, 5], [6, 7])) + print(list(it.filterfalse(lambda x: len(x) < 5, arr))) + return list(it.combinations("testing", 4)) + +a = ['Hello','my','name','is','Vasya'] +print(list_transform(a)) From 708b00662579ed6b92357e1655632e24a39eeb93 Mon Sep 17 00:00:00 2001 From: Bear346 <57682132+Bear346@users.noreply.github.com> Date: Tue, 27 Oct 2020 13:36:18 +0300 Subject: [PATCH 5/6] Create Lecture7.py --- Practice/MIsakichev/Lecture7.py | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Practice/MIsakichev/Lecture7.py diff --git a/Practice/MIsakichev/Lecture7.py b/Practice/MIsakichev/Lecture7.py new file mode 100644 index 00000000..bd519396 --- /dev/null +++ b/Practice/MIsakichev/Lecture7.py @@ -0,0 +1,92 @@ +#ЛЕКЦИЯ СЕМЬ +#task one +import datetime as dating + +def calculate_working_days(start, end): + + if start > end: + return "Uncorrect date" + else: + total = ((end - start).days)+ 1 + days = (int(total / 7)) + summary = days * 5 + + for key in range(days * 7 , total): + holyday = (start + dating.timedelta(key)).weekday() + if holyday!= 5 and holyday != 6: + summary = summary + 1 + return summary + +date_01 =dating.date(2015,4,11) +date_02 = dating.date(2020,4,11) +print(f'Количество дней = {calculate_working_days(date_01,date_02)}') +date_02 =dating.date(2015,4,11) +date_01 = dating.date(2020,4,11) +print(calculate_working_days(date_01,date_02)) + +#Task two +import subprocess + +def reading_file(name): + process = subprocess.Popen(['type', name], shell=True) + process.wait() + res = process.communicate() + if process.returncode: + return res +reading_file('test.txt') +print(" ") + +#Task three +import pickle +import random + + +class Human: + def __init__(self, first_name, surname, age, place,work): + self.first_name = first_name + self.surname = surname + self.age = age + self.place = place + self.work = work + + def __str__(self): + str = f'first_name = {self.first_name} , surname = {self.surname}, age = {self.age} , place = {self.place}, work = {self.work}' + return str + + +def create_people(ammount): + first_names = ['Alexander', 'Ivan', 'Kirill', 'Mikhail', 'Vasya'] + surname = ['Makarov', 'Bobrov', 'Svetlov', 'Ivanov', 'Klimov'] + place = ['Moscow', 'Nizhy_Novgorod', 'Kazan', 'New_York', 'Paris'] + work = ['developer', 'plumber', 'surgery', 'manager', 'tester'] + list= [] + if ammount > 0: + for key in range(ammount): + list.append(Human(random.choice(first_names), + random.choice(surname), + random.randint(18, 50), + random.choice(place), + random.choice(work))) + with open('human.data', 'wb') as readings: + j = 0 + while j < ammount: + pickle.dump(list[j], readings, protocol=pickle.HIGHEST_PROTOCOL) + j += 1 + elif ammount <= 0: + print("Количество должно быть больше нуля") + + return list + + +def printing_list(file, buffer): + with open(file, 'rb+') as files: + for key in buffer: + people_list = pickle.load(files) + print(f'{people_list}') + + +if __name__ == '__main__': + arr = create_people(5) + printing_list('human.data', arr) + arr = create_people(0) + printing_list('human.data',arr) From 7148a46b7d95b0d539531d471376018c1f7547d3 Mon Sep 17 00:00:00 2001 From: Bear346 <57682132+Bear346@users.noreply.github.com> Date: Tue, 27 Oct 2020 13:36:51 +0300 Subject: [PATCH 6/6] Create Lecture9.py --- Practice/MIsakichev/Lecture9.py | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Practice/MIsakichev/Lecture9.py diff --git a/Practice/MIsakichev/Lecture9.py b/Practice/MIsakichev/Lecture9.py new file mode 100644 index 00000000..3cd697a7 --- /dev/null +++ b/Practice/MIsakichev/Lecture9.py @@ -0,0 +1,64 @@ +#ЛЕКЦИЯ ДЕВЯТЬ +#task one +import time as t + +def find_primes(end,start): + starting = t.time() + list = [] + flag = True + for key in range(start, end): + for i in range(2, key): + if key % i == 0: + flag = False + break + if flag == True: + list.append(key) + + finish = t.time() + print(f"Время = {(finish - starting)} секунд") + return list + +for i in range(3): + starting = t.time() + find_primes(10000, 3) + find_primes(20000, 10001) + find_primes(30000, 20001) + break +print(" ") + +#Task two +from multiprocessing import Process + +def adding(*listing): + start = t.time() + if isinstance(listing[0], float) or isinstance(listing[0], int): + buffer = 0 + elif isinstance(listing[0], list): + buffer = list() + else: + buffer = '' + + for key in listing: + buffer += key + finish = t.time() + print('Веремени для сложения типа {}, затрачено {} sec.'.format(type(listing[0]), finish - start)) + print(buffer) + +if __name__ == '__main__': + arr = [ + ('zzzz','aaaa','ccccc'), + (124.3,15.4,77.8,), + (122,144,58,),([7,8,9,], + ['bbb','cccc'],[7.5,45.23,85.6],) + ] + def process(function, arr): + list = [] + for k in arr: + list.append(Process(target=function, args=k)) + for key in list: + key.start() + yield key + + list = list(process(adding, arr)) + for j in list: + j.join()