From a850be6ac15acd488c074229533549b03fcdb139 Mon Sep 17 00:00:00 2001 From: gitddpsm <37410949+gitddpsm@users.noreply.github.com> Date: Wed, 23 Dec 2020 12:42:39 +0300 Subject: [PATCH 1/7] Create a1 init branch create pull request --- a1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a1 diff --git a/a1 b/a1 new file mode 100644 index 0000000..e69de29 From 3111d2bf6525f340a88eac9a5ca6b51adae91956 Mon Sep 17 00:00:00 2001 From: Don Diamond Date: Fri, 8 Jan 2021 06:41:26 +0300 Subject: [PATCH 2/7] upd upd --- .vscode/settings.json | 3 +++ less_5_task1.py | 23 +++++++++++++++++++++++ a1 => lesson_5.txt | 0 3 files changed, 26 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 less_5_task1.py rename a1 => lesson_5.txt (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..62e1333 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "H:\\Python\\Python64_365\\python.exe" +} \ No newline at end of file diff --git a/less_5_task1.py b/less_5_task1.py new file mode 100644 index 0000000..07e9c95 --- /dev/null +++ b/less_5_task1.py @@ -0,0 +1,23 @@ +''' +Создать программно файл в текстовом формате, записать в него построчно данные, вводимые пользователем. Об окончании ввода данных свидетельствует пустая строка.''' + +text = [] + +def usr_input(): + while True: + string = input('>') + if string == '': + break + text.append(f'{string}\n') + +usr_input() +print(text) + +f = open("my_file", 'w') +f.writelines(text) +f.close() + + +with open("my_file", 'r') as f_obj: + for line in f_obj: + print(line) diff --git a/a1 b/lesson_5.txt similarity index 100% rename from a1 rename to lesson_5.txt From 8d6794b9752a2cb0959ea6eb7e5911c4c56dcda8 Mon Sep 17 00:00:00 2001 From: Don Diamond Date: Fri, 8 Jan 2021 07:38:43 +0300 Subject: [PATCH 3/7] upd task2 upd task2 --- .vscode/settings.json | 2 +- less_5_task2.py | 12 ++++++++++++ my_file | 10 ++++++++++ task2_file | 4 ++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 less_5_task2.py create mode 100644 my_file create mode 100644 task2_file diff --git a/.vscode/settings.json b/.vscode/settings.json index 62e1333..552fc5b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "python.pythonPath": "H:\\Python\\Python64_365\\python.exe" + "python.pythonPath": "H:\\Python\\Python64_391\\python39.exe" } \ No newline at end of file diff --git a/less_5_task2.py b/less_5_task2.py new file mode 100644 index 0000000..34ddea0 --- /dev/null +++ b/less_5_task2.py @@ -0,0 +1,12 @@ +''' +2. Создать текстовый файл (не программно), сохранить в нем несколько строк, выполнить подсчет количества строк, количества слов в каждой строке.''' + +with open("task2_file", 'r') as f_obj: + input_list = [] + line_num = 0 + for line in f_obj: + line_num += 1 + print(f' in line {line_num}: {len(line.split())} words') + input_list.append(line.replace('\n', '')) + f_obj.close() + print(f'{len(input_list)} lines in file\n') diff --git a/my_file b/my_file new file mode 100644 index 0000000..e413a41 --- /dev/null +++ b/my_file @@ -0,0 +1,10 @@ +sadas dsad +sasd asdsad +asdasdsa dsadasd + +asda sdsad + + + +asd +ads \ No newline at end of file diff --git a/task2_file b/task2_file new file mode 100644 index 0000000..5dec305 --- /dev/null +++ b/task2_file @@ -0,0 +1,4 @@ +? ??? ??? ????? ???????? ??? ?? ??? ?? ??????? +1 ????????? ??????????? - ?? ????????? words +2 ????? ??? ????????? ???????? ??? ??? ????? ?????? ?????? ????? ?? ??????? ???? ??? ?????? ?????? +3 ?????????? ???? ? line ????? ?????????? ???: \ No newline at end of file From a3cc8faf193a1982f2a794d54166cc4ae1a36fcb Mon Sep 17 00:00:00 2001 From: Don Diamond Date: Wed, 13 Jan 2021 21:23:40 +0300 Subject: [PATCH 4/7] HW upd hw upd --- employers_data.txt | 6 ++++++ less_5_task3.py | 19 +++++++++++++++++++ less_5_task4.py | 6 ++++++ my_file | 10 ---------- task2_file | 11 +++++++---- 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 employers_data.txt create mode 100644 less_5_task3.py create mode 100644 less_5_task4.py diff --git a/employers_data.txt b/employers_data.txt new file mode 100644 index 0000000..bd0fad8 --- /dev/null +++ b/employers_data.txt @@ -0,0 +1,6 @@ +Петров 50000 +Сидоров 40000 +Зверева 15000 +Пупкин 12000 +Калошина 10000 +Шизова 120000 \ No newline at end of file diff --git a/less_5_task3.py b/less_5_task3.py new file mode 100644 index 0000000..6a6868d --- /dev/null +++ b/less_5_task3.py @@ -0,0 +1,19 @@ +''' +Создать текстовый файл (не программно), построчно записать фамилии сотрудников и величину их окладов. Определить, кто из сотрудников имеет оклад менее 20 тыс., вывести фамилии этих сотрудников. Выполнить подсчет средней величины дохода сотрудников. +''' +import os + +file_name = 'employers_data.txt' +file_path = os.path.join(os.path.dirname(__file__), file_name) + +with open(file_path, 'r',encoding='UTF=8') as file: + file_data = file.read().split() + +work_dict = {item : int(file_data[index + 1]) for index, item in enumerate(file_data) if index % 2 == 0} + +# Фамилии сотрудников с окладом менее 20000 +print([key for key, value in work_dict.items() if any(value < 20000 for element in work_dict.values())]) + +# Средняя ЗП +value_list = [value for key, value in work_dict.items()] +print(sum(value_list) // len(value_list)) diff --git a/less_5_task4.py b/less_5_task4.py new file mode 100644 index 0000000..e7ccedf --- /dev/null +++ b/less_5_task4.py @@ -0,0 +1,6 @@ +'''4. Создать (не программно) текстовый файл со следующим содержимым: +One — 1 +Two — 2 +Three — 3 +Four — 4 +Необходимо написать программу, открывающую файл на чтение и считывающую построчно данные. При этом английские числительные должны заменяться на русские. Новый блок строк должен записываться в новый текстовый файл.''' \ No newline at end of file diff --git a/my_file b/my_file index e413a41..e69de29 100644 --- a/my_file +++ b/my_file @@ -1,10 +0,0 @@ -sadas dsad -sasd asdsad -asdasdsa dsadasd - -asda sdsad - - - -asd -ads \ No newline at end of file diff --git a/task2_file b/task2_file index 5dec305..c3d3b27 100644 --- a/task2_file +++ b/task2_file @@ -1,4 +1,7 @@ -? ??? ??? ????? ???????? ??? ?? ??? ?? ??????? -1 ????????? ??????????? - ?? ????????? words -2 ????? ??? ????????? ???????? ??? ??? ????? ?????? ?????? ????? ?? ??????? ???? ??? ?????? ?????? -3 ?????????? ???? ? line ????? ?????????? ???: \ No newline at end of file +ghghjgghj + +jhkjkjh ghjkjhkjh + +lkjlkjlklkj lkjlkjlkj lkjlkjj + +kljlkjlkjlk \ No newline at end of file From 83bff7795d394e987801523a8fd24d5616847b93 Mon Sep 17 00:00:00 2001 From: Don Diamond Date: Thu, 14 Jan 2021 19:21:38 +0300 Subject: [PATCH 5/7] L5 T4 Update HW --- .vscode/launch.json | 15 +++++++++++++++ .vscode/settings.json | 2 +- digits_spelling.txt | 4 ++++ less_5_task4.py | 31 ++++++++++++++++++++++++++++++- modyfied_spelling.txt | 4 ++++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 digits_spelling.txt create mode 100644 modyfied_spelling.txt diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..cbe53f1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Текущий файл", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ]`` +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 552fc5b..62e1333 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "python.pythonPath": "H:\\Python\\Python64_391\\python39.exe" + "python.pythonPath": "H:\\Python\\Python64_365\\python.exe" } \ No newline at end of file diff --git a/digits_spelling.txt b/digits_spelling.txt new file mode 100644 index 0000000..aca55a2 --- /dev/null +++ b/digits_spelling.txt @@ -0,0 +1,4 @@ +One — 1 +Two — 2 +Three — 3 +Four — 4 \ No newline at end of file diff --git a/less_5_task4.py b/less_5_task4.py index e7ccedf..10d0ea6 100644 --- a/less_5_task4.py +++ b/less_5_task4.py @@ -3,4 +3,33 @@ Two — 2 Three — 3 Four — 4 -Необходимо написать программу, открывающую файл на чтение и считывающую построчно данные. При этом английские числительные должны заменяться на русские. Новый блок строк должен записываться в новый текстовый файл.''' \ No newline at end of file +Необходимо написать программу, открывающую файл на чтение и считывающую построчно данные. При этом английские числительные должны заменяться на русские. Новый блок строк должен записываться в новый текстовый файл.''' + +import os + +file_full_path = os.path.join(os.path.dirname(__file__), 'digits_spelling.txt') +mfile_full_path = os.path.join(os.path.dirname(__file__), 'modyfied_spelling.txt') + +replace_cheme = { + 'One' : 'Один', + 'Two' : 'Два', + 'Three' : 'Три', + 'Four' : 'Четыре' +} + +write_line = '' +with open(mfile_full_path, 'w', encoding='UTF-8') as file_out: + print('Clear out File') + +with open(file_full_path, 'r', encoding='UTF-8') as file_in: + for line in file_in: + in_line = line.replace('\n', '').split(' — ') + for element in in_line: + try: + if element != any(replace_cheme.keys()): + write_line += replace_cheme[element] + ' — ' + except KeyError: + write_line += element + '\n' + with open(mfile_full_path, 'a', encoding='UTF-8') as file_out: + file_out.writelines(write_line) + write_line = '' diff --git a/modyfied_spelling.txt b/modyfied_spelling.txt new file mode 100644 index 0000000..44109a1 --- /dev/null +++ b/modyfied_spelling.txt @@ -0,0 +1,4 @@ +Один — 1 +Два — 2 +Три — 3 +Четыре — 4 From 6c363c7c49a8fe9788695c42d56229199b2f303c Mon Sep 17 00:00:00 2001 From: Don Diamond Date: Fri, 15 Jan 2021 17:03:44 +0300 Subject: [PATCH 6/7] friday commin Homework Update --- .vscode/launch.json | 2 +- generated | 1 + learn_plan | 4 ++++ less_5_task4.py | 1 + less_5_task5.py | 19 +++++++++++++++++++ less_5_task6.py | 31 +++++++++++++++++++++++++++++++ my_file | 5 +++++ 7 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 generated create mode 100644 learn_plan create mode 100644 less_5_task5.py create mode 100644 less_5_task6.py diff --git a/.vscode/launch.json b/.vscode/launch.json index cbe53f1..9829b87 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,5 +11,5 @@ "program": "${file}", "console": "integratedTerminal" } - ]`` + ] } \ No newline at end of file diff --git a/generated b/generated new file mode 100644 index 0000000..7c965b3 --- /dev/null +++ b/generated @@ -0,0 +1 @@ +6 12 7 20 2 14 6 20 12 19 \ No newline at end of file diff --git a/learn_plan b/learn_plan new file mode 100644 index 0000000..c57171d --- /dev/null +++ b/learn_plan @@ -0,0 +1,4 @@ +Информатика: 100(л) 50(пр) 20(лаб) +Физика: 30(л) — 10(лаб) +Физкультура: — 30(пр) — +Python практика: - 120(пр) 20(лаб) \ No newline at end of file diff --git a/less_5_task4.py b/less_5_task4.py index 10d0ea6..8e1bdde 100644 --- a/less_5_task4.py +++ b/less_5_task4.py @@ -20,6 +20,7 @@ write_line = '' with open(mfile_full_path, 'w', encoding='UTF-8') as file_out: print('Clear out File') + file_out.close() with open(file_full_path, 'r', encoding='UTF-8') as file_in: for line in file_in: diff --git a/less_5_task5.py b/less_5_task5.py new file mode 100644 index 0000000..f9a814b --- /dev/null +++ b/less_5_task5.py @@ -0,0 +1,19 @@ +'''5. Создать (программно) текстовый файл, записать в него программно набор чисел, разделенных пробелами. Программа должна подсчитывать сумму чисел в файле и выводить ее на экран. +''' + +from random import randint +from os import path + +file_path = path.join(path.dirname(__file__), 'generated') +number_list = [randint(1, 20) for i in range(randint(5,10))] +nums_string = ' '.join(str(el) for el in number_list) + +with open(file_path, 'w', encoding='UTF-8') as file: + file.writelines(nums_string) + +summ = 0 +with open(file_path, 'r') as file: + for line in file: + for x in line.split(' '): + summ += int(x) +print(summ) diff --git a/less_5_task6.py b/less_5_task6.py new file mode 100644 index 0000000..62fad27 --- /dev/null +++ b/less_5_task6.py @@ -0,0 +1,31 @@ +'''6. Необходимо создать (не программно) текстовый файл, где каждая строка описывает учебный предмет и наличие лекционных, практических и лабораторных занятий по этому предмету и их количество. Важно, чтобы для каждого предмета не обязательно были все типы занятий. Сформировать словарь, содержащий название предмета и общее количество занятий по нему. Вывести словарь на экран. +Примеры строк файла: + +Информатика: 100(л) 50(пр) 20(лаб). +Физика: 30(л) — 10(лаб) +Физкультура: — 30(пр) — +Пример словаря: + +{“Информатика”: 170, “Физика”: 40, “Физкультура”: 30}''' + +from random import randint +from os import path + +file_content = [] +with open(path.join(path.dirname(__file__), 'learn_plan'), 'r', encoding='UTF-8') as file: + for line in file: + file_content.append(line) +print(content) + +''' +number_list = [randint(1, 20) for i in range(randint(5,10))] +nums_string = ' '.join(str(el) for el in number_list) + + +summ = 0 +with open(file_path, 'r') as file: + for line in file: + for x in line.split(' '): + summ += int(x) +print(summ) +''' \ No newline at end of file diff --git a/my_file b/my_file index e69de29..af0ce2d 100644 --- a/my_file +++ b/my_file @@ -0,0 +1,5 @@ +lkjdslkj +sdfkl; +sdfk +dsf +sdf From 1df17213ec68e0cc278bd5e087e7040edc62b72f Mon Sep 17 00:00:00 2001 From: Don Diamond Date: Sun, 17 Jan 2021 23:40:18 +0300 Subject: [PATCH 7/7] less 5 complete UPD --- firm_data_in | 12 ++++++++++++ firm_data_out | 1 + less_5_task5.py | 1 + less_5_task6.py | 27 +++++++++++++-------------- less_5_task7.py | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 firm_data_in create mode 100644 firm_data_out create mode 100644 less_5_task7.py diff --git a/firm_data_in b/firm_data_in new file mode 100644 index 0000000..d0e73f2 --- /dev/null +++ b/firm_data_in @@ -0,0 +1,12 @@ +firm_1 ООО 10000 2000 +firm_2 ООО 20000 5000 +firm_3 АОЗТ 10000 5000 +firm_4 ООО 10000 5000 +firm_5 ОАО 30000 5000 +firm_6 ООО 10000 5000 +firm_7 ИП 4000 5000 +firm_8 ООО 10000 5000 +firm_9 ИП 3000 5000 +firm_10 ООО 10000 5000 +firm_11 АОЗТ 5000 15000 +firm_12 ООО 10000 5000 diff --git a/firm_data_out b/firm_data_out new file mode 100644 index 0000000..100263a --- /dev/null +++ b/firm_data_out @@ -0,0 +1 @@ +[{"firm_1": 8000, "firm_2": 15000, "firm_3": 5000, "firm_4": 5000, "firm_5": 25000, "firm_6": 5000, "firm_8": 5000, "firm_10": 5000, "firm_12": 5000}, {"average profit": 8666.67}] \ No newline at end of file diff --git a/less_5_task5.py b/less_5_task5.py index f9a814b..c738bb4 100644 --- a/less_5_task5.py +++ b/less_5_task5.py @@ -5,6 +5,7 @@ from os import path file_path = path.join(path.dirname(__file__), 'generated') + number_list = [randint(1, 20) for i in range(randint(5,10))] nums_string = ' '.join(str(el) for el in number_list) diff --git a/less_5_task6.py b/less_5_task6.py index 62fad27..c85df17 100644 --- a/less_5_task6.py +++ b/less_5_task6.py @@ -11,21 +11,20 @@ from random import randint from os import path -file_content = [] +file_content = {} with open(path.join(path.dirname(__file__), 'learn_plan'), 'r', encoding='UTF-8') as file: for line in file: - file_content.append(line) -print(content) + line_content = line.split(':') + file_content[line_content[0]] = line_content[1].split() -''' -number_list = [randint(1, 20) for i in range(randint(5,10))] -nums_string = ' '.join(str(el) for el in number_list) +output_dict = {} +for key,value in file_content.items(): + output_dict[key] = 0 + for item in value: + try: + output_dict[key] += int(item.split('(')[0]) + except ValueError: + continue - -summ = 0 -with open(file_path, 'r') as file: - for line in file: - for x in line.split(' '): - summ += int(x) -print(summ) -''' \ No newline at end of file +print(output_dict) + \ No newline at end of file diff --git a/less_5_task7.py b/less_5_task7.py new file mode 100644 index 0000000..03dd057 --- /dev/null +++ b/less_5_task7.py @@ -0,0 +1,40 @@ +'''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 os + +''' + +import os +import json + +file_data_in = os.path.join(os.path.dirname(__file__), 'firm_data_in') +file_data_out = os.path.join(os.path.dirname(__file__), 'firm_data_out') +firm_data_all = {} +firm_data_positive = {} +sum_profit = 0 + +with open(file_data_in, 'r', encoding='UTF-8') as file_in: + for line in file_in: + line_parse = line.replace('\n','').split() + profit = int(line_parse[2]) - int(line_parse[3]) + firm_data_all[line_parse[0]] = profit + if profit > 0: + firm_data_positive[line_parse[0]] = profit + sum_profit += profit + +a_profit ={ + 'average profit': round(sum_profit / len(firm_data_positive), 2) + } +#print(f" average profit: {a_profit.get('average profit')}") +with open(file_data_out, 'w', encoding='utf-8') as file_out: + out_data = [firm_data_positive, a_profit] + json.dump(out_data, file_out)