From 4971166885dd1b2b666ae3de9f1691dfdc43b3a8 Mon Sep 17 00:00:00 2001 From: AvokrichA Date: Wed, 24 Nov 2021 21:48:10 +0300 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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