From f18c049436f2db360ef8e088174dc1f15d6eb3cc Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 15:20:39 +0300 Subject: [PATCH 01/18] Init task-1 --- task-1.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 task-1.py diff --git a/task-1.py b/task-1.py new file mode 100644 index 0000000..b0e9c09 --- /dev/null +++ b/task-1.py @@ -0,0 +1,5 @@ +""" +Задание: +Создать программно файл в текстовом формате, записать в него построчно данные, вводимые пользователем. +Об окончании ввода данных свидетельствует пустая строка. +""" \ No newline at end of file From ade989a9eb82b883542f2ccdbb24804623078bca Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 15:27:53 +0300 Subject: [PATCH 02/18] Comp task-1 --- task-1.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/task-1.py b/task-1.py index b0e9c09..39b0f00 100644 --- a/task-1.py +++ b/task-1.py @@ -2,4 +2,14 @@ Задание: Создать программно файл в текстовом формате, записать в него построчно данные, вводимые пользователем. Об окончании ввода данных свидетельствует пустая строка. -""" \ No newline at end of file +""" + + +print("Введите текст, для выхода введите пустую строку.") + +with open(file="task-1.txt", mode="a+", encoding="utf-8") as fh: + while True: + user_line = input("") + if not len(user_line): + break + fh.write(user_line + "\n") From b884987f356319bee1bc3340f44e96e46cf2d6e7 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 15:30:31 +0300 Subject: [PATCH 03/18] Init task-2 --- task-2.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 task-2.py diff --git a/task-2.py b/task-2.py new file mode 100644 index 0000000..e2e1a0f --- /dev/null +++ b/task-2.py @@ -0,0 +1,5 @@ +""" +Задание: +Создать текстовый файл (не программно), сохранить в нем несколько строк, +выполнить подсчет количества строк, количества слов в каждой строке. +""" \ No newline at end of file From 00117c653c9b8e6289291a88ffbe355ec6f0e280 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 15:30:44 +0300 Subject: [PATCH 04/18] add text to task-2 --- sample.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sample.txt diff --git a/sample.txt b/sample.txt new file mode 100644 index 0000000..cc58b7f --- /dev/null +++ b/sample.txt @@ -0,0 +1,14 @@ +Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document. +To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries. +Themes and styles also help keep your document coordinated. When you click Design and choose a new Theme, the pictures, charts, and SmartArt graphics change to match your new theme. When you apply styles, your headings change to match the new theme. +Save time in Word with new buttons that show up where you need them. To change the way a picture fits in your document, click it and a button for layout options appears next to it. When you work on a table, click where you want to add a row or a column, and then click the plus sign. +Reading is easier, too, in the new Reading view. You can collapse parts of the document and focus on the text you want. If you need to stop reading before you reach the end, Word remembers where you left off - even on another device. +Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document. +To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries. +Themes and styles also help keep your document coordinated. When you click Design and choose a new Theme, the pictures, charts, and SmartArt graphics change to match your new theme. When you apply styles, your headings change to match the new theme. +Save time in Word with new buttons that show up where you need them. To change the way a picture fits in your document, click it and a button for layout options appears next to it. When you work on a table, click where you want to add a row or a column, and then click the plus sign. +Reading is easier, too, in the new Reading view. You can collapse parts of the document and focus on the text you want. If you need to stop reading before you reach the end, Word remembers where you left off - even on another device. +Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document. +To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries. +Themes and styles also help keep your document coordinated. When you click Design and choose a new Theme, the pictures, charts, and SmartArt graphics change to match your new theme. When you apply styles, your headings change to match the new theme. +Save time in Word with new buttons that show up where you need them. To change the way a picture fits in your document, click it and a button for layout options appears next to it. When you work on a table, click where you want to add a row or a column, and then click the plus sign. \ No newline at end of file From 847b3848255f73e80ee78a8bb2aea1d42e363095 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 15:35:29 +0300 Subject: [PATCH 05/18] Comp task-2 --- task-2.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/task-2.py b/task-2.py index e2e1a0f..4c5e66b 100644 --- a/task-2.py +++ b/task-2.py @@ -2,4 +2,12 @@ Задание: Создать текстовый файл (не программно), сохранить в нем несколько строк, выполнить подсчет количества строк, количества слов в каждой строке. -""" \ No newline at end of file +""" + +line_counter = 0 +with open(file="sample.txt", mode="r") as fh: + for line in fh: + line_counter += 1 + word_counter = len(line.split()) + print("В строке {} всего {} слов(а)".format(line_counter, word_counter)) +print("Всего строк: {}".format(line_counter)) From 921770133789bd7135120fefd029691a928f09d5 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 16:23:01 +0300 Subject: [PATCH 06/18] Init task-3 --- task-3.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 task-3.py diff --git a/task-3.py b/task-3.py new file mode 100644 index 0000000..7a6be36 --- /dev/null +++ b/task-3.py @@ -0,0 +1,10 @@ +""" +Задание: +Создать текстовый файл (не программно), +построчно записать фамилии сотрудников и величину их окладов (не менее 10 строк). +Определить, кто из сотрудников имеет оклад менее 20 тыс., вывести фамилии этих сотрудников. +Выполнить подсчет средней величины дохода сотрудников. +Пример файла: +Иванов 23543.12 +Петров 13749.32 +""" From 0174678798fe9267392ff487f0395771c1f62f13 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 16:23:10 +0300 Subject: [PATCH 07/18] Add file to task-3 --- account.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 account.txt diff --git a/account.txt b/account.txt new file mode 100644 index 0000000..ee398b9 --- /dev/null +++ b/account.txt @@ -0,0 +1,10 @@ +Быкова 15425.79 +Иванов 20286.18 +Петров 15126.36 +Сидоров 13518.40 +Козлов 22058.20 +Иванова 18416.20 +Долгополова 14037.65 +Митрошина 19804.16 +Кузнецов 21639.79 +Парфёнов 16629.20 \ No newline at end of file From 61fbd6c180d54521e3177ca6d6e6560c7c3768a3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 16:23:20 +0300 Subject: [PATCH 08/18] Comp task-3 --- task-3.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/task-3.py b/task-3.py index 7a6be36..065157f 100644 --- a/task-3.py +++ b/task-3.py @@ -8,3 +8,16 @@ Иванов 23543.12 Петров 13749.32 """ + +sum = 0 +count = 0 + +with open(file="account.txt", mode="r", encoding="utf-8") as fo: + for line in fo: + name, income = line.split() + income = float(income) + count += 1 + sum += income + if income < 20000: + print("У сотрудника {} ЗП меньше 20к ({})".format(name, income)) +print("Средняя ЗП {}".format(sum / count)) From 3d33c2a9a8b7b882de036900139b48d56b1a9d5d Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 17:39:36 +0300 Subject: [PATCH 09/18] Init task-4 --- task-4.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 task-4.py diff --git a/task-4.py b/task-4.py new file mode 100644 index 0000000..04ef4e0 --- /dev/null +++ b/task-4.py @@ -0,0 +1,11 @@ +""" +Задание: +Создать (не программно) текстовый файл со следующим содержимым: +One — 1 +Two — 2 +Three — 3 +Four — 4 +Необходимо написать программу, открывающую файл на чтение и считывающую построчно данные. +При этом английские числительные должны заменяться на русские. +Новый блок строк должен записываться в новый текстовый файл. +""" From dcbefb7d4bf52d284a08ef0313c87d19355acbae Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 17:39:47 +0300 Subject: [PATCH 10/18] Add file for task-4 --- numbers.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 numbers.txt diff --git a/numbers.txt b/numbers.txt new file mode 100644 index 0000000..aca55a2 --- /dev/null +++ b/numbers.txt @@ -0,0 +1,4 @@ +One — 1 +Two — 2 +Three — 3 +Four — 4 \ No newline at end of file From b6d872c1e88e7285efcc50d948b0e6ec3c6d40cb Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 23 Jul 2020 17:39:58 +0300 Subject: [PATCH 11/18] Comp task-4 --- task-4.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/task-4.py b/task-4.py index 04ef4e0..72e4fc3 100644 --- a/task-4.py +++ b/task-4.py @@ -9,3 +9,12 @@ При этом английские числительные должны заменяться на русские. Новый блок строк должен записываться в новый текстовый файл. """ + + +dic = {"One": "Один", "Two": "Два", "Three": "Три", "Four": "Четыре"} + +with open(file="numbers_another.txt", mode="a", encoding="utf-8") as fo0: + with open(file="numbers.txt", mode="r", encoding="utf-8") as fo1: + for line in fo1: + my_list = line.split() + print("{} {} {}".format(dic[my_list[0]], my_list[1], my_list[2]), file=fo0) \ No newline at end of file From b3d499e9f39f2c60426ad65af7e2a97cb7472d76 Mon Sep 17 00:00:00 2001 From: Andrey Yushkov Date: Sat, 25 Jul 2020 15:43:54 +0300 Subject: [PATCH 12/18] Init task-5 --- task-5.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 task-5.py diff --git a/task-5.py b/task-5.py new file mode 100644 index 0000000..5c8eb34 --- /dev/null +++ b/task-5.py @@ -0,0 +1,6 @@ +""" +Задание: +Создать (программно) текстовый файл, записать в него программно набор чисел, разделенных пробелами. +Программа должна подсчитывать сумму чисел в файле и выводить ее на экран. +""" + From d85a789447b3c4724478de58b4dd2b4d2bf5da01 Mon Sep 17 00:00:00 2001 From: Andrey Yushkov Date: Sat, 25 Jul 2020 16:27:45 +0300 Subject: [PATCH 13/18] Comp task-5 --- task-5.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/task-5.py b/task-5.py index 5c8eb34..23fd010 100644 --- a/task-5.py +++ b/task-5.py @@ -4,3 +4,15 @@ Программа должна подсчитывать сумму чисел в файле и выводить ее на экран. """ +import random +import functools + +with open(file="task-5.txt", mode="w+") as of: + print(" ".join( + [str(random.randint(-1000, 1000)) for i in range(1, random.randint(5, 10))] + ), file=of) + of.seek(0) + sum = 0 + for ln in of: + sum += functools.reduce((lambda a, b: int(a) + int(b)), ln.split()) +print("Cумма чисел в файле {}".format(sum)) From 505a7fc4ccc6e662bbbdc3d593b689273f17f067 Mon Sep 17 00:00:00 2001 From: Andrey Yushkov Date: Sat, 25 Jul 2020 16:29:53 +0300 Subject: [PATCH 14/18] Init task-5 --- task-6.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 task-6.py diff --git a/task-6.py b/task-6.py new file mode 100644 index 0000000..79e5a5b --- /dev/null +++ b/task-6.py @@ -0,0 +1,11 @@ +""" +Задание: +Необходимо создать (не программно) текстовый файл, где каждая строка описывает учебный предмет и наличие лекционных, +практических и лабораторных занятий по этому предмету и их количество. +Важно, чтобы для каждого предмета не обязательно были все типы занятий. Сформировать словарь, +содержащий название предмета и общее количество занятий по нему. Вывести словарь на экран. +Примеры строк файла: Информатика: 100(л) 50(пр) 20(лаб). + Физика: 30(л) — 10(лаб) + Физкультура: — 30(пр) — +Пример словаря: {“Информатика”: 170, “Физика”: 40, “Физкультура”: 30} +""" \ No newline at end of file From 32005cbe4be24b02c7a07c112c67207082983de9 Mon Sep 17 00:00:00 2001 From: Andrey Yushkov Date: Sat, 25 Jul 2020 16:37:04 +0300 Subject: [PATCH 15/18] Init task-6 --- task-6.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/task-6.py b/task-6.py index 79e5a5b..1adcbe5 100644 --- a/task-6.py +++ b/task-6.py @@ -8,4 +8,7 @@ Физика: 30(л) — 10(лаб) Физкультура: — 30(пр) — Пример словаря: {“Информатика”: 170, “Физика”: 40, “Физкультура”: 30} -""" \ No newline at end of file +""" + + + From bf5b35ef48e42b8d940b280d1d798b4cc55e37e0 Mon Sep 17 00:00:00 2001 From: Andrey Yushkov Date: Sat, 25 Jul 2020 17:36:59 +0300 Subject: [PATCH 16/18] Comp task-6 --- task-6.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/task-6.py b/task-6.py index 1adcbe5..cd49542 100644 --- a/task-6.py +++ b/task-6.py @@ -10,5 +10,27 @@ Пример словаря: {“Информатика”: 170, “Физика”: 40, “Физкультура”: 30} """ +import re +import locale + +locale.setlocale(locale.LC_ALL, "ru_RU") +exp = re.compile(r'(\w+)\:\s+(((\d{1,})\(\w+\)|—)\s+)(((\d{1,})\(\w+\)|—)\s+)(((\d{1,})\(\w+\)|—)).?') + +dict = {} + +with open(file="task-6.txt", mode="r") as of: + for line in of: + res = exp.match(line) + sum = 0 + if len(res.groups()) == 10: + if not res.group(4) is None: + sum += int(res.group(4)) + if not res.group(7) is None: + sum += int(res.group(7)) + if not res.group(10) is None: + sum += int(res.group(10)) + dict[res.group(1)] = sum + +print("Cловаря: ", dict) \ No newline at end of file From c408b83b903e47adff2f745fdc1ae31c13579204 Mon Sep 17 00:00:00 2001 From: Andrey Yushkov Date: Sat, 25 Jul 2020 17:37:07 +0300 Subject: [PATCH 17/18] exampl task-6 --- task-6.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 task-6.txt diff --git a/task-6.txt b/task-6.txt new file mode 100644 index 0000000..9d4d7b4 --- /dev/null +++ b/task-6.txt @@ -0,0 +1,3 @@ +Информатика: 100(л) 50(пр) 20(лаб). +Физика: 30(л) — 10(лаб) +Физкультура: — 30(пр) — \ No newline at end of file From 16edc3ff3c525d2df07cc36f0a9c0d649263f029 Mon Sep 17 00:00:00 2001 From: Andrey Yushkov Date: Sat, 25 Jul 2020 17:38:58 +0300 Subject: [PATCH 18/18] Init task-7 --- task-7.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 task-7.py diff --git a/task-7.py b/task-7.py new file mode 100644 index 0000000..cfde16c --- /dev/null +++ b/task-7.py @@ -0,0 +1,15 @@ +""" +Создать вручную и заполнить несколькими строками текстовый файл, +в котором каждая строка должна содержать данные о фирме: название, форма собственности, выручка, издержки. +Пример строки файла: 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}] +Подсказка: использовать менеджер контекста. +""" +