From 4971166885dd1b2b666ae3de9f1691dfdc43b3a8 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Wed, 24 Nov 2021 21:48:10 +0300 Subject: [PATCH 01/13] l5 --- Lesson_5/Les5_Task1.py | 8 ++++++++ Lesson_5/Les5_Task2.py | 11 +++++++++++ Lesson_5/Text.txt | 7 +++++++ 3 files changed, 26 insertions(+) create mode 100644 Lesson_5/Les5_Task1.py create mode 100644 Lesson_5/Les5_Task2.py create mode 100644 Lesson_5/Text.txt diff --git a/Lesson_5/Les5_Task1.py b/Lesson_5/Les5_Task1.py new file mode 100644 index 0000000..5f5382d --- /dev/null +++ b/Lesson_5/Les5_Task1.py @@ -0,0 +1,8 @@ + +with open("text.txt", 'r') as file_obj: + content = file_obj.read() + end = () + print(content) + for i in content: + print(i) + diff --git a/Lesson_5/Les5_Task2.py b/Lesson_5/Les5_Task2.py new file mode 100644 index 0000000..4053b2b --- /dev/null +++ b/Lesson_5/Les5_Task2.py @@ -0,0 +1,11 @@ + +with open("text.txt", 'r') as file_obj: + content = (file_obj.readlines()) + print('В файле Text',len(content),'строк') + for i in range(len(content)): + content_1 = content[i].split() + print('В', i + 1,'строке', len(content_1), 'слов(а)') + print(content) + + + diff --git a/Lesson_5/Text.txt b/Lesson_5/Text.txt new file mode 100644 index 0000000..60ca598 --- /dev/null +++ b/Lesson_5/Text.txt @@ -0,0 +1,7 @@ +Hello! +My name is Olesia +I am studying at the online university "Geek Brains" +bla-bla +bla bla bla +bla +bla-bla, bla, bla From 0ec715d26d4fedcfabbcd0c2677310509ad2fe03 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Wed, 24 Nov 2021 21:51:17 +0300 Subject: [PATCH 02/13] l5 --- Lesson_5/Les5_Task3.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Lesson_5/Les5_Task3.py diff --git a/Lesson_5/Les5_Task3.py b/Lesson_5/Les5_Task3.py new file mode 100644 index 0000000..ecf9f58 --- /dev/null +++ b/Lesson_5/Les5_Task3.py @@ -0,0 +1,17 @@ +with open('L5_t3.txt', 'r', encoding='UTF-8') as my_file: + my_list=tuple(my_file.read().split('\n')) + print(my_list, sep=':') + + + + + # sal = [] + # poor = [] + # my_list = my_file.read().split('\n') + # print(my_list) + # for i in my_list: + # i = i.split() + # if float(i[::2]) < 20000: + # poor.append(i[0]) + # sal.append(i[::2]) + # print(f'Оклад меньше 20.000 {poor}, средний оклад {sum(map(float, sal)) / len(sal)}') From e6b7c2ea1c8d8b1d4d7220b54b3638ae390d62d7 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Thu, 25 Nov 2021 17:08:46 +0300 Subject: [PATCH 03/13] l5 --- Lesson_5/L5_t3.txt | 10 ++++++++++ Lesson_5/Les5_Task3.py | 25 +++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 Lesson_5/L5_t3.txt diff --git a/Lesson_5/L5_t3.txt b/Lesson_5/L5_t3.txt new file mode 100644 index 0000000..65e23cf --- /dev/null +++ b/Lesson_5/L5_t3.txt @@ -0,0 +1,10 @@ +Иванов 15245.23 +Петров 56325.35 +Чирков 95354.23 +Сидоров 56353.22 +Задорнов 18321.44 +Алексеев 62354.12 +Сергеев 35543.32 +Александров 35435.24 +Владимиров 36533.24 +Смирнов 16355.6 diff --git a/Lesson_5/Les5_Task3.py b/Lesson_5/Les5_Task3.py index ecf9f58..80f2f08 100644 --- a/Lesson_5/Les5_Task3.py +++ b/Lesson_5/Les5_Task3.py @@ -1,17 +1,18 @@ with open('L5_t3.txt', 'r', encoding='UTF-8') as my_file: - my_list=tuple(my_file.read().split('\n')) - print(my_list, sep=':') + i = 0 + s = 0 + print('Список сотрудников с окладом менее 20000:') + while True: + my_list = my_file.readline() + if not my_list: + break + if float(my_list.split(' ')[1]) < 20000: + print(my_list.split(' ')[0]) + s += float(my_list.split(' ')[1]) + i += 1 + + print('Средняя величина дохода сотрудников:', s/i) - # sal = [] - # poor = [] - # my_list = my_file.read().split('\n') - # print(my_list) - # for i in my_list: - # i = i.split() - # if float(i[::2]) < 20000: - # poor.append(i[0]) - # sal.append(i[::2]) - # print(f'Оклад меньше 20.000 {poor}, средний оклад {sum(map(float, sal)) / len(sal)}') From 5aaaeda25928ad3ceec239dc562168d76a123050 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Mon, 29 Nov 2021 16:55:15 +0300 Subject: [PATCH 04/13] l5 --- Lesson_5/L5_T4.txt | 4 +++ Lesson_5/L5_T6.py | 58 ++++++++++++++++++++++++++++++++++++++++++ Lesson_5/L5_T7.py | 34 +++++++++++++++++++++++++ Lesson_5/Les5_T5.py | 28 ++++++++++++++++++++ Lesson_5/Les5_T6.txt | 3 +++ Lesson_5/Les5_Task3.py | 2 +- Lesson_5/Les5_Task4.py | 14 ++++++++++ Lesson_5/Les5_t7.txt | 3 +++ 8 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 Lesson_5/L5_T4.txt create mode 100644 Lesson_5/L5_T6.py create mode 100644 Lesson_5/L5_T7.py create mode 100644 Lesson_5/Les5_T5.py create mode 100644 Lesson_5/Les5_T6.txt create mode 100644 Lesson_5/Les5_Task4.py create mode 100644 Lesson_5/Les5_t7.txt diff --git a/Lesson_5/L5_T4.txt b/Lesson_5/L5_T4.txt new file mode 100644 index 0000000..48de98b --- /dev/null +++ b/Lesson_5/L5_T4.txt @@ -0,0 +1,4 @@ +One - 1 +Two - 2 +Three - 3 +Four - 4 \ No newline at end of file diff --git a/Lesson_5/L5_T6.py b/Lesson_5/L5_T6.py new file mode 100644 index 0000000..9568cde --- /dev/null +++ b/Lesson_5/L5_T6.py @@ -0,0 +1,58 @@ +# Необходимо создать (не программно) текстовый файл, +# где каждая строка описывает учебный предмет и наличие лекционных, практических и лабораторных занятий +# по этому предмету и их количество. +# Важно, чтобы для каждого предмета не обязательно были все типы занятий. +# Сформировать словарь, содержащий название предмета и общее количество занятий по нему. +# Вывести словарь на экран. +# Примеры строк файла: +# Информатика: 100(л) 50(пр) 20(лаб). +# Физика: 30(л) — 10(лаб) +# Физкультура: — 30(пр) — +# +# Пример словаря: +# {“Информатика”: 170, “Физика”: 40, “Физкультура”: 30} + +d = {} +with open('Les5_T6.txt', 'r', encoding='UTF-8') as f_obj: + while True: + s=0 + f_obj_line=f_obj.readline() + if not f_obj_line: + break + key_value = f_obj_line.split(" ") + for i in key_value[1:]: + j='' + for x in range(len(i)): + if i[x].isdigit(): + j+=i[x] + if j != '': + s+= int(j) + d[key_value[0][0:-1]] = s +print(d) + + + + # for line in f_obj_line: + # key_value = line.split(" ") + # value = 0 + # for i in d: + # list=d(i) + # if i.isdigit(): + # value+=i + # else: + # break + # for j in sum_value: + # s_value+= sum_value(j) + # print(s_value) + + + + + + + + + + + + diff --git a/Lesson_5/L5_T7.py b/Lesson_5/L5_T7.py new file mode 100644 index 0000000..46f9dc6 --- /dev/null +++ b/Lesson_5/L5_T7.py @@ -0,0 +1,34 @@ +# 7. Создать (не программно) текстовый файл, в котором каждая строка должна содержать данные о фирме: +# название, форма собственности, выручка, издержки. +# Пример строки файла: firm_1 ООО 10000 5000. +# Необходимо построчно прочитать файл, вычислить прибыль каждой компании, а также среднюю прибыль. +# Если фирма получила убытки, в расчет средней прибыли ее не включать. +# Далее реализовать список. Он должен содержать словарь с фирмами и их прибылями, а также словарь со средней прибылью. Если фирма получила убытки, также добавить ее в словарь (со значением убытков). +# Пример списка: [{“firm_1”: 5000, “firm_2”: 3000, “firm_3”: 1000}, {“average_profit”: 2000}]. +# Итоговый список сохранить в виде json-объекта в соответствующий файл. +# Пример json-объекта: +# [{"firm_1": 5000, "firm_2": 3000, "firm_3": 1000}, {"average_profit": 2000}] +# +# Подсказка: использовать менеджеры контекста. + +import json + +list1={} +med_prft={} +rev=0 +costs=0 +with open('L5_T7.py','r', encoding='UTF-8') as f_obj: + while True: + my_file = f_obj.readline().split() + if not my_file: + break + prft = int(my_file[2]) - int(my_file[3]) + if prft>0: + rev+=1 + s += prft + list1[my_file[0]]=prft +med_prft=costs/rev +result = [list1, med_prft] +print(result) +with open("result.json", 'w', encoding='utf-8') as f_obj: + json.dump(result, f_obj) diff --git a/Lesson_5/Les5_T5.py b/Lesson_5/Les5_T5.py new file mode 100644 index 0000000..42ee64b --- /dev/null +++ b/Lesson_5/Les5_T5.py @@ -0,0 +1,28 @@ +# Создать (программно) текстовый файл, записать в него программно набор чисел, +# разделенных пробелами. Программа должна подсчитывать сумму чисел в файле и +# выводить ее на экран. + +def num(string): + total = 0 + for number in string: + total += int(number) + return total +my_file = open('L5_T5.txt', 'w+') +my_list = input("Введите числа через пробел:") +my_file.write(my_list) +my_file.seek(0) +my_list1 = my_file.read() +my_list2=my_list1.split(' ') +print(num(my_list2)) + +my_file.close() + + + + + +# sum_num2=() +# with open("L5_T5.txt", "w+") as my_list: +# my_list.write(int(input('Введите числа через пробел:').split(' '))) +# my_list.append(sum_num2) +# print(sum(sum_num2)) diff --git a/Lesson_5/Les5_T6.txt b/Lesson_5/Les5_T6.txt new file mode 100644 index 0000000..b2b260e --- /dev/null +++ b/Lesson_5/Les5_T6.txt @@ -0,0 +1,3 @@ +Информатика: 100(л) 70(пр) 40(лаб). +Физика: 70(л) — 90(лаб) +Физкультура: — 40(пр) — \ No newline at end of file diff --git a/Lesson_5/Les5_Task3.py b/Lesson_5/Les5_Task3.py index 80f2f08..979ecb7 100644 --- a/Lesson_5/Les5_Task3.py +++ b/Lesson_5/Les5_Task3.py @@ -11,7 +11,7 @@ s += float(my_list.split(' ')[1]) i += 1 - print('Средняя величина дохода сотрудников:', s/i) + print('Средняя заработная плата сотрудников:', s/i) diff --git a/Lesson_5/Les5_Task4.py b/Lesson_5/Les5_Task4.py new file mode 100644 index 0000000..5585273 --- /dev/null +++ b/Lesson_5/Les5_Task4.py @@ -0,0 +1,14 @@ +with open('L5_T4.txt', encoding='UTF-8') as f_obj: + for line in f_obj: + print(line) +rus_dict = {'One' : 'Один', 'Two' : 'Два', 'Three' : 'Три', 'Four' : 'Четыре'} +new_dict = [] +with open('L5_T4.txt') as f_obj: + for i in f_obj: + i = i.split(' ', 1) + new_dict.append(rus_dict[i[0]] + i[1]) + print(new_dict) + +with open('L5_T4_1.txt', 'w', encoding='UTF-8') as file_obj_1: + file_obj_1.writelines(new_dict) + diff --git a/Lesson_5/Les5_t7.txt b/Lesson_5/Les5_t7.txt new file mode 100644 index 0000000..f0adb3b --- /dev/null +++ b/Lesson_5/Les5_t7.txt @@ -0,0 +1,3 @@ +firm_1 OOO 10000 4000 +firm_2 OOO 30000 200000 +firm_3 OOO 20000 50000 From c54947ee1c3ec7dd7e0d2d197858f3ddbeed052a Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Mon, 29 Nov 2021 23:11:59 +0300 Subject: [PATCH 05/13] l5 --- Lesson_5/L5_T7.py | 4 ++-- Lesson_5/Les5_T5.py | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/Lesson_5/L5_T7.py b/Lesson_5/L5_T7.py index 46f9dc6..4069255 100644 --- a/Lesson_5/L5_T7.py +++ b/Lesson_5/L5_T7.py @@ -17,7 +17,7 @@ med_prft={} rev=0 costs=0 -with open('L5_T7.py','r', encoding='UTF-8') as f_obj: +with open('Les5_t7.txt','r', encoding='UTF-8') as f_obj: while True: my_file = f_obj.readline().split() if not my_file: @@ -25,7 +25,7 @@ prft = int(my_file[2]) - int(my_file[3]) if prft>0: rev+=1 - s += prft + costs += prft list1[my_file[0]]=prft med_prft=costs/rev result = [list1, med_prft] diff --git a/Lesson_5/Les5_T5.py b/Lesson_5/Les5_T5.py index 42ee64b..d5f1eff 100644 --- a/Lesson_5/Les5_T5.py +++ b/Lesson_5/Les5_T5.py @@ -16,13 +16,3 @@ def num(string): print(num(my_list2)) my_file.close() - - - - - -# sum_num2=() -# with open("L5_T5.txt", "w+") as my_list: -# my_list.write(int(input('Введите числа через пробел:').split(' '))) -# my_list.append(sum_num2) -# print(sum(sum_num2)) From 2868e3850bcb18fcdb054ea6819a6724dfc35e35 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Mon, 29 Nov 2021 23:13:24 +0300 Subject: [PATCH 06/13] l5 t7 corr --- .idea/.gitignore | 3 +++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ .../\320\236\321\201\320\275\320\276\320\262\321\213.iml" | 8 ++++++++ Lesson_5/L5_T4_1.txt | 4 ++++ Lesson_5/L5_T5.txt | 1 + Lesson_5/file_4_new.txt | 4 ++++ Lesson_5/result.json | 1 + 10 files changed, 45 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 ".idea/\320\236\321\201\320\275\320\276\320\262\321\213.iml" create mode 100644 Lesson_5/L5_T4_1.txt create mode 100644 Lesson_5/L5_T5.txt create mode 100644 Lesson_5/file_4_new.txt create mode 100644 Lesson_5/result.json diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d56657a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2572635 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/.idea/\320\236\321\201\320\275\320\276\320\262\321\213.iml" "b/.idea/\320\236\321\201\320\275\320\276\320\262\321\213.iml" new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ "b/.idea/\320\236\321\201\320\275\320\276\320\262\321\213.iml" @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lesson_5/L5_T4_1.txt b/Lesson_5/L5_T4_1.txt new file mode 100644 index 0000000..8d7d0ba --- /dev/null +++ b/Lesson_5/L5_T4_1.txt @@ -0,0 +1,4 @@ +Один- 1 +Два- 2 +Три- 3 +Четыре- 4 \ No newline at end of file diff --git a/Lesson_5/L5_T5.txt b/Lesson_5/L5_T5.txt new file mode 100644 index 0000000..a498169 --- /dev/null +++ b/Lesson_5/L5_T5.txt @@ -0,0 +1 @@ +3 33 \ No newline at end of file diff --git a/Lesson_5/file_4_new.txt b/Lesson_5/file_4_new.txt new file mode 100644 index 0000000..9329294 --- /dev/null +++ b/Lesson_5/file_4_new.txt @@ -0,0 +1,4 @@ +���� - 1 +��� - 2 +��� - 3 +������ - 4 \ No newline at end of file diff --git a/Lesson_5/result.json b/Lesson_5/result.json new file mode 100644 index 0000000..aed233d --- /dev/null +++ b/Lesson_5/result.json @@ -0,0 +1 @@ +[{"firm_1": 6000, "firm_2": -170000, "firm_3": -30000}, 6000.0] \ No newline at end of file From 4f1d63cab582609ba7a1de0d41f30193ee4e3d63 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Sat, 4 Dec 2021 16:42:22 +0300 Subject: [PATCH 07/13] l6 t1 --- Lesson_6/Les6_Task1.py | 18 ++++++++++++++++++ Lesson_6/Les6_t1.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Lesson_6/Les6_Task1.py create mode 100644 Lesson_6/Les6_t1.py diff --git a/Lesson_6/Les6_Task1.py b/Lesson_6/Les6_Task1.py new file mode 100644 index 0000000..55573cb --- /dev/null +++ b/Lesson_6/Les6_Task1.py @@ -0,0 +1,18 @@ +from time import sleep + +class TrafficLight: + colors = ('red', 'yellow', 'green') + time = (7, 2, 5) + + def __init__(self): + self.__color= 'red' + + def running(self): + for i in self.colors: + self.__color = i + print(self.__color) + sleep(self.time[self.colors.index(self.__color)]) + +traffic = TrafficLight() +traffic.running() + diff --git a/Lesson_6/Les6_t1.py b/Lesson_6/Les6_t1.py new file mode 100644 index 0000000..ea8105b --- /dev/null +++ b/Lesson_6/Les6_t1.py @@ -0,0 +1,43 @@ +class Dish: +#создаем конструктор + def __init__(self, title, country, weight): + self.title = title # создаем атрибут(self.title) и передаем значение(title) + self.country = country + self.weight = weight +#создаем метод + def get_title_and_country(self): #принято всегда указывать self (можно назвать по друому, + # но это плохой тон в среде программистов, сюда же можно передавать любые параметры, через запятую после self) + return f'{self.title} from {self.country}' + +#создаем класс потомок + +class SpicyDish(Dish): #если название из двух слов, пишем каждое слово с большой буквы, не используем разделитель(пробел, подчеркивание и пр) + def __init__(self, title, country, weight): + self.title = title # создаем атрибут(self.title) и передаем значение(title) + self.country = country + self.weight = weight + self.spicy = True #создаем новый атрибут (любое, в этом случае булево значение) + + #создаем еще один новый атрибут + def get_info(self): + return ('This is spicy dish!') + +#создаем новый объект +my_spicy_dish = SpicyDish('Harcho', 'Georgia', 500) + + +my_Dish1 = Dish('Pasta', 'Italy', '300') #создаем объект внутри конструктора (переменную my_Dish1), обязательно указываем класс (Dish) и передаем параметры +my_Dish2 = Dish('Borcsh', 'Ucraine', '350') +# print(my_Dish1.title) +# print(my_Dish1.country) +# print(my_Dish1.weight) +# print(my_Dish1.get_title_and_country()) +print(my_spicy_dish.spicy) +print(my_spicy_dish.get_info()) + + + + + + + From 0038adfe99eaffb831072c5425872eb0ce0915be Mon Sep 17 00:00:00 2001 From: Alexandra Chirkova <93881730+AvokrichA@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:44:57 +0300 Subject: [PATCH 08/13] Delete Les6_t1.py --- Lesson_6/Les6_t1.py | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 Lesson_6/Les6_t1.py diff --git a/Lesson_6/Les6_t1.py b/Lesson_6/Les6_t1.py deleted file mode 100644 index ea8105b..0000000 --- a/Lesson_6/Les6_t1.py +++ /dev/null @@ -1,43 +0,0 @@ -class Dish: -#создаем конструктор - def __init__(self, title, country, weight): - self.title = title # создаем атрибут(self.title) и передаем значение(title) - self.country = country - self.weight = weight -#создаем метод - def get_title_and_country(self): #принято всегда указывать self (можно назвать по друому, - # но это плохой тон в среде программистов, сюда же можно передавать любые параметры, через запятую после self) - return f'{self.title} from {self.country}' - -#создаем класс потомок - -class SpicyDish(Dish): #если название из двух слов, пишем каждое слово с большой буквы, не используем разделитель(пробел, подчеркивание и пр) - def __init__(self, title, country, weight): - self.title = title # создаем атрибут(self.title) и передаем значение(title) - self.country = country - self.weight = weight - self.spicy = True #создаем новый атрибут (любое, в этом случае булево значение) - - #создаем еще один новый атрибут - def get_info(self): - return ('This is spicy dish!') - -#создаем новый объект -my_spicy_dish = SpicyDish('Harcho', 'Georgia', 500) - - -my_Dish1 = Dish('Pasta', 'Italy', '300') #создаем объект внутри конструктора (переменную my_Dish1), обязательно указываем класс (Dish) и передаем параметры -my_Dish2 = Dish('Borcsh', 'Ucraine', '350') -# print(my_Dish1.title) -# print(my_Dish1.country) -# print(my_Dish1.weight) -# print(my_Dish1.get_title_and_country()) -print(my_spicy_dish.spicy) -print(my_spicy_dish.get_info()) - - - - - - - From 0b986b13e45fcb6019090da5d434c32c8e04af0c Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Sat, 4 Dec 2021 17:37:31 +0300 Subject: [PATCH 09/13] Les6Task2 --- Lesson_6/Les6_Task2.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Lesson_6/Les6_Task2.py diff --git a/Lesson_6/Les6_Task2.py b/Lesson_6/Les6_Task2.py new file mode 100644 index 0000000..232f736 --- /dev/null +++ b/Lesson_6/Les6_Task2.py @@ -0,0 +1,18 @@ +# Реализовать класс Road (дорога), в котором определить атрибуты: +# length (длина), width (ширина). Значения данных атрибутов должны передаваться при создании +# экземпляра класса. Атрибуты сделать защищенными. Определить метод расчета массы асфальта, +# необходимого для покрытия всего дорожного полотна. Использовать формулу: +# длина * ширина * масса асфальта для покрытия одного кв метра дороги асфальтом, +# # толщиной в 1 см * чи сло см толщины полотна. Проверить работу метода. + +class Road: + def __init__(self, lenght, widht): + self._lenght = lenght + self._widht = widht + + def get_weight(self, mass, layer): + return self._lenght* self._widht * mass * layer/1000 + +m = Road(100, 4) +print(m.get_weight(0.145, 6)) + From aff73a63e8a610edfec219687539f6a877f087b7 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Sat, 4 Dec 2021 17:38:49 +0300 Subject: [PATCH 10/13] Les6Task2 --- Lesson_6/Les6_Task2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lesson_6/Les6_Task2.py b/Lesson_6/Les6_Task2.py index 232f736..6ecf238 100644 --- a/Lesson_6/Les6_Task2.py +++ b/Lesson_6/Les6_Task2.py @@ -15,4 +15,3 @@ def get_weight(self, mass, layer): m = Road(100, 4) print(m.get_weight(0.145, 6)) - From b015682867f545065cc5a9fa44237f1c770e9e05 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Sat, 4 Dec 2021 18:16:08 +0300 Subject: [PATCH 11/13] Les6Task3 --- Lesson_6/Less6_Task3.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Lesson_6/Less6_Task3.py diff --git a/Lesson_6/Less6_Task3.py b/Lesson_6/Less6_Task3.py new file mode 100644 index 0000000..aa5a8a4 --- /dev/null +++ b/Lesson_6/Less6_Task3.py @@ -0,0 +1,38 @@ +# Реализовать базовый класс Worker (работник), в котором определить атрибуты: +# name, surname, position (должность), income (доход). Последний атрибут должен быть защищенным +# и ссылаться на словарь, содержащий элементы: оклад и премия, например, +# {"wage": wage, "bonus": bonus}. Создать класс Position (должность) на базе класса Worker. +# В классе Position реализовать методы получения полного имени сотрудника (get_full_name) и дохода +# с учетом премии (get_total_income). Проверить работу примера на реальных данных +# (создать экземпляры класса Position, передать данные, проверить значения атрибутов, вызвать методы экземпляров). + +class Worker: + def __init__(self, name, surname, position, wage, bonus): + self.name = name # создаем атрибут(self.title) и передаем значение(title) + self.surname = surname + self.position = position + self._income = {"wage": wage, "bonus": bonus} + +class Position(Worker): + + def get_full_name(self): + return self.name, self.surname + + def get_total_income(self): + return self._income['wage']+self._income['bonus'] + +worker_1 = Position('Иван', 'Иванов', 'Менеджер', 50000, 10000) + +print(worker_1.position, worker_1.get_full_name(),worker_1.get_total_income()) + +# print(worker_1.name) +# print(worker_1.surname) +# print(worker_1.position) +# print(worker_1.get_full_name()) +# print(worker_1.get_total_income()) + + + + + + From e86c05a80e046406bffab7c8b8d9b7c6a47561e4 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Sat, 4 Dec 2021 19:18:14 +0300 Subject: [PATCH 12/13] Les6Task4 --- Lesson_6/Less6_Task4.py | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Lesson_6/Less6_Task4.py diff --git a/Lesson_6/Less6_Task4.py b/Lesson_6/Less6_Task4.py new file mode 100644 index 0000000..c9c3c97 --- /dev/null +++ b/Lesson_6/Less6_Task4.py @@ -0,0 +1,65 @@ +# Реализуйте базовый класс Car. У данного класса должны быть следующие атрибуты: +# speed, color, name, is_police (булево). А также методы: go, stop, turn(direction), +# которые должны сообщать, что машина поехала, остановилась, повернула (куда). +# Опишите несколько дочерних классов: TownCar, SportCar, WorkCar, PoliceCar. Добавьте в базовый класс метод show_speed, +# который должен показывать текущую скорость автомобиля. Для классов TownCar и WorkCar переопределите метод show_speed. +# При значении скорости свыше 60 (TownCar) и 40 (WorkCar) должно выводиться сообщение о превышении скорости. +# Создайте экземпляры классов, передайте значения атрибутов. +# Выполните доступ к атрибутам, выведите результат. Выполните вызов методов и также покажите результат. + +class Car: + def __init__(self, speed, color, name, is_police=False): + self.speed = speed + self.color = color + self.name = name + self.is_police = is_police + def go(self): + print('Go!') + def stop(self): + print('stop') + def turn(self, direction): + print({direction}) + def show_speed(self): + print(self.speed) + +class TownCar(Car): + def show_speed(self): + if self.speed >60: + print('Превышение скорости!') + +class SportCar(Car): + print('') + + +class WorkCar(Car): + def show_speed(self): + if self.speed >40: + print('Превышение скорости!') + +class PoliceCar(Car): + def __init__(self, speed, color, name, is_police=True): + self.speed = speed + self.color = color + self.name = name + self.is_police = is_police + + +TownCar_1=TownCar(90, 'red', 'Kia') +SportCar_1=SportCar(180, 'Black', 'Ferrari') +WorkCar_1=WorkCar(140, 'White', 'Gaz') +PoliceCar_1=PoliceCar(60, 'Blue', 'Toyota') + + +print(TownCar_1.name,TownCar_1.speed, TownCar_1.color,TownCar_1.is_police) +TownCar_1.show_speed() +TownCar_1.stop() + +print(SportCar_1.name, SportCar_1.speed, SportCar_1.color, SportCar_1.is_police) +SportCar_1.turn('Прямо') + +print(WorkCar_1.name, WorkCar_1.speed,WorkCar_1.color, WorkCar_1.is_police) +WorkCar_1.show_speed() +WorkCar_1.turn('Направо') + +print(PoliceCar_1.name, PoliceCar_1.speed,PoliceCar_1.color, PoliceCar_1.is_police) +PoliceCar_1.turn('Налево') From 319f19cc21a556b29aa886f992148d52f2e8e26d Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Sat, 4 Dec 2021 19:44:42 +0300 Subject: [PATCH 13/13] Les6Task5 --- Lesson_6/Les6_Task5.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Lesson_6/Les6_Task5.py diff --git a/Lesson_6/Les6_Task5.py b/Lesson_6/Les6_Task5.py new file mode 100644 index 0000000..5fc1444 --- /dev/null +++ b/Lesson_6/Les6_Task5.py @@ -0,0 +1,32 @@ +# Реализовать класс Stationery (канцелярская принадлежность). +# Определить в нем атрибут title (название) и метод draw (отрисовка). +# Метод выводит сообщение “Запуск отрисовки.” Создать три дочерних класса Pen (ручка), Pencil (карандаш), +# Handle (маркер). В каждом из классов реализовать переопределение метода draw. +# Для каждого из классов методы должен выводить уникальное сообщение. +# Создать экземпляры классов и проверить, что выведет описанный метод для каждого экземпляра. + +class Stationery: + def __init__(self, title): + self.title = title + + def draw(self): + print('Запуск отрисовки') + +class Pen(Stationery): + def draw(self): + print('Рисовать ручкой', self.title) + +class Pensil(Stationery): + def draw(self): + print('Рисовать карандашом', self.title) + +class Handle(Stationery): + def draw(self): + print('Рисовать маркером', self.title) + +pen_1 = Pen('Линия 0,7 мм') +pensil_1 = Pensil('Линия 2 мм') +handle_1 = Handle('Линия 4 мм') + +for i in (pen_1, pensil_1, handle_1): + i.draw()