From 31c5c0cd2d220eb0f8f4021cb91dec4a1a2a2dbd Mon Sep 17 00:00:00 2001 From: Crazymax21 Date: Fri, 13 May 2022 10:16:39 +1000 Subject: [PATCH 1/8] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=E2=84=961=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=20=E2=84=965?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lesson 5/Task_1.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Lesson 5/Task_1.py diff --git a/Lesson 5/Task_1.py b/Lesson 5/Task_1.py new file mode 100644 index 0000000..c2b8625 --- /dev/null +++ b/Lesson 5/Task_1.py @@ -0,0 +1,13 @@ +# 1. Создать программный файл в текстовом формате, записать в него построчно данные, +# вводимые пользователем. Об окончании ввода данных будет свидетельствовать пустая +# строка. + + +from itertools import count + +with open('lesson1.txt', 'w') as lesson1_file: + for i in count(0): + user_string = input(f'Введите строку №{i + 1}: ') + if str == '': + break + print(user_string, file=lesson1_file) From 83a0e5d614801dc0a130e8ba607b7c076a0fbcdb Mon Sep 17 00:00:00 2001 From: Crazymax21 Date: Fri, 13 May 2022 10:34:55 +1000 Subject: [PATCH 2/8] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=E2=84=962=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=20=E2=84=965?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- .idea/pythoncourse.iml | 2 +- Lesson 5/Task_2.py | 13 +++++++++++++ Lesson 5/lesson1.txt | 9 +++++++++ Lesson 5/lesson2.txt | 9 +++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Lesson 5/Task_2.py create mode 100644 Lesson 5/lesson1.txt create mode 100644 Lesson 5/lesson2.txt diff --git a/.idea/misc.xml b/.idea/misc.xml index 0749876..2849f27 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/pythoncourse.iml b/.idea/pythoncourse.iml index 8437fe6..f63fa7b 100644 --- a/.idea/pythoncourse.iml +++ b/.idea/pythoncourse.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/Lesson 5/Task_2.py b/Lesson 5/Task_2.py new file mode 100644 index 0000000..2323981 --- /dev/null +++ b/Lesson 5/Task_2.py @@ -0,0 +1,13 @@ +# 2. Создать текстовый файл (не программно), сохранить в нём несколько строк, выполнить +# подсчёт строк и слов в каждой строке. + +string_count = 0 +words_count = 0 + +with open('lesson2.txt','r', encoding="utf-8") as lesson2_file: + for file_string in lesson2_file: + string_count += 1 + words_count = len(file_string.split(' ')) + print(f'В строке №{string_count} - {words_count} слов') + + diff --git a/Lesson 5/lesson1.txt b/Lesson 5/lesson1.txt new file mode 100644 index 0000000..a794ecf --- /dev/null +++ b/Lesson 5/lesson1.txt @@ -0,0 +1,9 @@ +При этом выражением может быть как одна +так и несколько инструкций. Условием может быть +любое истинное +или ненулевое значение. +Выражение будет повторяться, +пока условие будет истинным. +Когда условие становится ложным +интерпретатор переводит выполнение программы +на строку, следующую за \ No newline at end of file diff --git a/Lesson 5/lesson2.txt b/Lesson 5/lesson2.txt new file mode 100644 index 0000000..a794ecf --- /dev/null +++ b/Lesson 5/lesson2.txt @@ -0,0 +1,9 @@ +При этом выражением может быть как одна +так и несколько инструкций. Условием может быть +любое истинное +или ненулевое значение. +Выражение будет повторяться, +пока условие будет истинным. +Когда условие становится ложным +интерпретатор переводит выполнение программы +на строку, следующую за \ No newline at end of file From 20a46b24ccaee7ed08b268d9ac10a51414df7ee2 Mon Sep 17 00:00:00 2001 From: Crazymax21 Date: Fri, 13 May 2022 10:38:14 +1000 Subject: [PATCH 3/8] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=87=D1=83=D1=82=D1=8C=20=D0=B8=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=B9=20=D1=87=D0=B8?= =?UTF-8?q?=D1=82=D0=B0=D0=B5=D0=BC=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lesson 5/Task_1.py | 4 ++-- Lesson 5/Task_2.py | 4 ++-- Lesson 5/Task_3.py | 8 ++++++++ Lesson 5/lesson2.txt | 9 --------- Lesson 5/{lesson1.txt => task_2.txt} | 0 5 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 Lesson 5/Task_3.py delete mode 100644 Lesson 5/lesson2.txt rename Lesson 5/{lesson1.txt => task_2.txt} (100%) diff --git a/Lesson 5/Task_1.py b/Lesson 5/Task_1.py index c2b8625..f789448 100644 --- a/Lesson 5/Task_1.py +++ b/Lesson 5/Task_1.py @@ -5,9 +5,9 @@ from itertools import count -with open('lesson1.txt', 'w') as lesson1_file: +with open('task_1.txt', 'w') as task1_file: for i in count(0): user_string = input(f'Введите строку №{i + 1}: ') if str == '': break - print(user_string, file=lesson1_file) + print(user_string, file=task1_file) diff --git a/Lesson 5/Task_2.py b/Lesson 5/Task_2.py index 2323981..6fdec60 100644 --- a/Lesson 5/Task_2.py +++ b/Lesson 5/Task_2.py @@ -4,8 +4,8 @@ string_count = 0 words_count = 0 -with open('lesson2.txt','r', encoding="utf-8") as lesson2_file: - for file_string in lesson2_file: +with open('task_2.txt', 'r', encoding="utf-8") as task2_file: + for file_string in task2_file: string_count += 1 words_count = len(file_string.split(' ')) print(f'В строке №{string_count} - {words_count} слов') diff --git a/Lesson 5/Task_3.py b/Lesson 5/Task_3.py new file mode 100644 index 0000000..98b794c --- /dev/null +++ b/Lesson 5/Task_3.py @@ -0,0 +1,8 @@ +# 3. Создать текстовый файл (не программно). Построчно записать фамилии сотрудников и +# величину их окладов (не менее 10 строк). Определить, кто из сотрудников имеет оклад менее +# 20 тысяч, вывести фамилии этих сотрудников. Выполнить подсчёт средней величины дохода +# сотрудников. +# Пример файла: +# Иванов 23543.12 +# Петров 13749.32 + diff --git a/Lesson 5/lesson2.txt b/Lesson 5/lesson2.txt deleted file mode 100644 index a794ecf..0000000 --- a/Lesson 5/lesson2.txt +++ /dev/null @@ -1,9 +0,0 @@ -При этом выражением может быть как одна -так и несколько инструкций. Условием может быть -любое истинное -или ненулевое значение. -Выражение будет повторяться, -пока условие будет истинным. -Когда условие становится ложным -интерпретатор переводит выполнение программы -на строку, следующую за \ No newline at end of file diff --git a/Lesson 5/lesson1.txt b/Lesson 5/task_2.txt similarity index 100% rename from Lesson 5/lesson1.txt rename to Lesson 5/task_2.txt From aa975e5087a3da64a84be5888f78de8d79346613 Mon Sep 17 00:00:00 2001 From: Crazymax21 Date: Fri, 13 May 2022 10:53:34 +1000 Subject: [PATCH 4/8] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=203=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=20=E2=84=965=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BF=D0=BE=D0=BB=D0=B5=D0=BD=D0=BD=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lesson 5/Task_3.py | 15 +++++++++++++++ Lesson 5/task_3.txt | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Lesson 5/task_3.txt diff --git a/Lesson 5/Task_3.py b/Lesson 5/Task_3.py index 98b794c..5c20f73 100644 --- a/Lesson 5/Task_3.py +++ b/Lesson 5/Task_3.py @@ -6,3 +6,18 @@ # Иванов 23543.12 # Петров 13749.32 +average_sum = 0 +staff_count = 0 + +with open('task_3.txt', 'r', encoding='utf-8') as task3_file: + print(f'Сотрудники с зарплатой менее 20000:') + for person_data in task3_file.read().split('\n'): + person_data_list = person_data.split(' ') + if int(person_data_list[1]) < 20000: + print(f'{person_data_list}') + staff_count += 1 + average_sum += int(person_data_list[1]) + print('Средняя зарплата сотрудников: ', average_sum/staff_count) + + + diff --git a/Lesson 5/task_3.txt b/Lesson 5/task_3.txt new file mode 100644 index 0000000..09341d4 --- /dev/null +++ b/Lesson 5/task_3.txt @@ -0,0 +1,10 @@ +Иванов 10000 +Петров 20000 +Сидоров 15000 +Чижов 5000 +Синицын 7000 +Журавлев 25000 +Аистов 27000 +Воробьев 28000 +Снегирев 4000 +Уткин 9500 \ No newline at end of file From c1f8a2514874e915185953f97bbe1c7e10acabd4 Mon Sep 17 00:00:00 2001 From: Crazymax21 Date: Fri, 13 May 2022 11:12:15 +1000 Subject: [PATCH 5/8] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=204=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=20=E2=84=965=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BF=D0=BE=D0=BB=D0=B5=D0=BD=D0=BD=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lesson 5/Task_4.py | 21 +++++++++++++++++++++ Lesson 5/task_4.txt | 4 ++++ Lesson 5/task_4_rus.txt | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 Lesson 5/Task_4.py create mode 100644 Lesson 5/task_4.txt create mode 100644 Lesson 5/task_4_rus.txt diff --git a/Lesson 5/Task_4.py b/Lesson 5/Task_4.py new file mode 100644 index 0000000..80960f8 --- /dev/null +++ b/Lesson 5/Task_4.py @@ -0,0 +1,21 @@ +# 4. Создать (не программно) текстовый файл со следующим содержимым: +# One — 1 +# Two — 2 +# Three — 3 +# Four — 4 +# Напишите программу, открывающую файл на чтение и считывающую построчно данные. При +# этом английские числительные должны заменяться на русские. Новый блок строк должен +# записываться в новый текстовый файл. + +digits = { + '1':'Один', + '2':'Два', + '3':'Три', + '4':'Четыре' +} + +with open('task_4.txt', 'r', encoding='utf-8') as task4_file: + with open('task_4_rus.txt', 'w', encoding='utf-8') as task4rus_file: + for file_string in task4_file.read().split('\n'): + print(f'{digits[file_string.split(" — ")[1]]} - {file_string.split(" — ")[1]}') + print(f'{digits[file_string.split(" — ")[1]]} - {file_string.split(" — ")[1]}', file=task4rus_file) diff --git a/Lesson 5/task_4.txt b/Lesson 5/task_4.txt new file mode 100644 index 0000000..aca55a2 --- /dev/null +++ b/Lesson 5/task_4.txt @@ -0,0 +1,4 @@ +One — 1 +Two — 2 +Three — 3 +Four — 4 \ No newline at end of file diff --git a/Lesson 5/task_4_rus.txt b/Lesson 5/task_4_rus.txt new file mode 100644 index 0000000..ab95344 --- /dev/null +++ b/Lesson 5/task_4_rus.txt @@ -0,0 +1,4 @@ +Один - 1 +Два - 2 +Три - 3 +Четыре - 4 From 1babd5899c16801035380e3f03da31dacefd6a9b Mon Sep 17 00:00:00 2001 From: Crazymax21 Date: Fri, 13 May 2022 11:36:53 +1000 Subject: [PATCH 6/8] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=205=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=20=E2=84=965=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BF=D0=BE=D0=BB=D0=B5=D0=BD=D0=BD=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lesson 5/Task_5.py | 13 +++++++++++++ Lesson 5/task_5.txt | 1 + 2 files changed, 14 insertions(+) create mode 100644 Lesson 5/Task_5.py create mode 100644 Lesson 5/task_5.txt diff --git a/Lesson 5/Task_5.py b/Lesson 5/Task_5.py new file mode 100644 index 0000000..30a3ea1 --- /dev/null +++ b/Lesson 5/Task_5.py @@ -0,0 +1,13 @@ +# 5. Создать (программно) текстовый файл, записать в него программно набор чисел, разделённых +# пробелами. Программа должна подсчитывать сумму чисел в файле и выводить её на экран. +from random import randint +from math import fsum + +digit_list = [str(randint(1, 100)) for el in range(10)] + +with open('task_5.txt', 'w', encoding='utf-8') as task5_file: + print(' '.join(digit_list), file=task5_file) + +with open('task_5.txt', 'r', encoding='utf-8') as task5_file: + digit_list = [int(el) for el in task5_file.read().split(' ')] + print(f'Сумма чисел: {digit_list} = {sum(digit_list)}') diff --git a/Lesson 5/task_5.txt b/Lesson 5/task_5.txt new file mode 100644 index 0000000..edcb616 --- /dev/null +++ b/Lesson 5/task_5.txt @@ -0,0 +1 @@ +27 58 65 49 11 35 56 46 92 44 From 00f945c3ea3647f220f663b140827e1cbc7b3481 Mon Sep 17 00:00:00 2001 From: Crazymax21 Date: Fri, 13 May 2022 16:33:20 +1000 Subject: [PATCH 7/8] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=206=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=20=E2=84=965=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BF=D0=BE=D0=BB=D0=B5=D0=BD=D0=BD=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lesson 5/Task_6.py | 20 ++++++++++++++++++++ Lesson 5/task_6.txt | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 Lesson 5/Task_6.py create mode 100644 Lesson 5/task_6.txt diff --git a/Lesson 5/Task_6.py b/Lesson 5/Task_6.py new file mode 100644 index 0000000..b20cf64 --- /dev/null +++ b/Lesson 5/Task_6.py @@ -0,0 +1,20 @@ +# 6. Сформировать (не программно) текстовый файл. В нём каждая строка должна описывать +# учебный предмет и наличие лекционных, практических и лабораторных занятий по предмету. +# Сюда должно входить и количество занятий. Необязательно, чтобы для каждого предмета +# были все типы занятий. +# Сформировать словарь, содержащий название предмета и общее количество занятий по +# нему. Вывести его на экран. +# Примеры строк файла: Информатика: 100(л) 50(пр) 20(лаб). +# Физика: 30(л) — 10(лаб) +# Физкультура: — 30(пр) — +# Пример словаря: {“Информатика”: 170, “Физика”: 40, “Физкультура”: 30} + +our_dict = {} +with open('task_6.txt', 'r', encoding='utf-8') as task6_file: + for file_string in task6_file.read().split('\n'): + our_list = file_string.split(': ') + print(our_list[1].split(' ')) + hours = sum([int(el.split('(')[0]) if el.split('(')[0].isdigit() else 0 for el in our_list[1].split(' ')]) + our_dict[our_list[0]] = hours + +print(our_dict) diff --git a/Lesson 5/task_6.txt b/Lesson 5/task_6.txt new file mode 100644 index 0000000..8f9782c --- /dev/null +++ b/Lesson 5/task_6.txt @@ -0,0 +1,6 @@ +Информатика: 100(л) 50(пр) 20(лаб) +Физика: 30(л) — 10(лаб) +Физкультура: — 30(пр) — +Химия: 100(л) 50(пр) 20(лаб) +Системотехника: 100(л) — 20(лаб) +Электротехника: 60(л) 25(пр) — \ No newline at end of file From b7af53130c72def836d585f5b2947981d3dc9111 Mon Sep 17 00:00:00 2001 From: Crazymax21 Date: Fri, 13 May 2022 17:04:47 +1000 Subject: [PATCH 8/8] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=207=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=20=E2=84=965=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BF=D0=BE=D0=BB=D0=B5=D0=BD=D0=BD=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lesson 5/Task_7.py | 35 +++++++++++++++++++++++++++++++++++ Lesson 5/Task_7.txt | 6 ++++++ Lesson 5/task_7.json | 1 + 3 files changed, 42 insertions(+) create mode 100644 Lesson 5/Task_7.py create mode 100644 Lesson 5/Task_7.txt create mode 100644 Lesson 5/task_7.json diff --git a/Lesson 5/Task_7.py b/Lesson 5/Task_7.py new file mode 100644 index 0000000..60b3c6c --- /dev/null +++ b/Lesson 5/Task_7.py @@ -0,0 +1,35 @@ +# 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 + +firm_list = [] +firm_dict = {} +firm_profit_list = [] + +with open('task_7.txt', 'r', encoding='utf-8') as task7_file: + strings_list = task7_file.read().split('\n') + for string in strings_list: + firm_data = string.split(' ') + firm_profit = int(firm_data[2]) - int(firm_data[3]) + firm_dict[firm_data[0]] = firm_profit + if firm_profit > 0: + firm_profit_list.append(firm_profit) + +firm_list.append(firm_dict) +firm_list.append({'average_profit': round(sum(firm_profit_list) / len(firm_profit_list), 2)}) + +print(firm_list) + +with open('task_7.json', 'w', encoding='utf-8') as task7_json_file: + json.dump(firm_list, task7_json_file) diff --git a/Lesson 5/Task_7.txt b/Lesson 5/Task_7.txt new file mode 100644 index 0000000..8b5bd7f --- /dev/null +++ b/Lesson 5/Task_7.txt @@ -0,0 +1,6 @@ +firm_1 ООО 10000 5000 +firm_2 О2О 100000 50000 +firm_3 ОО1 1000 50000 +firm_4 ОО3 8000 9000 +firm_5 2ОО 10000 1000 +firm_6 О3О 6000 7000 \ No newline at end of file diff --git a/Lesson 5/task_7.json b/Lesson 5/task_7.json new file mode 100644 index 0000000..db7b713 --- /dev/null +++ b/Lesson 5/task_7.json @@ -0,0 +1 @@ +[{"firm_1": 5000, "firm_2": 50000, "firm_3": -49000, "firm_4": -1000, "firm_5": 9000, "firm_6": -1000}, {"average_profit": 21333.33}] \ No newline at end of file