Skip to content
10 changes: 10 additions & 0 deletions account.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Быкова 15425.79
Иванов 20286.18
Петров 15126.36
Сидоров 13518.40
Козлов 22058.20
Иванова 18416.20
Долгополова 14037.65
Митрошина 19804.16
Кузнецов 21639.79
Парфёнов 16629.20
4 changes: 4 additions & 0 deletions numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
One — 1
Two — 2
Three — 3
Four — 4
14 changes: 14 additions & 0 deletions sample.txt
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions task-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Задание:
Создать программно файл в текстовом формате, записать в него построчно данные, вводимые пользователем.
Об окончании ввода данных свидетельствует пустая строка.
"""


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")
13 changes: 13 additions & 0 deletions task-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Задание:
Создать текстовый файл (не программно), сохранить в нем несколько строк,
выполнить подсчет количества строк, количества слов в каждой строке.
"""

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))
23 changes: 23 additions & 0 deletions task-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Задание:
Создать текстовый файл (не программно),
построчно записать фамилии сотрудников и величину их окладов (не менее 10 строк).
Определить, кто из сотрудников имеет оклад менее 20 тыс., вывести фамилии этих сотрудников.
Выполнить подсчет средней величины дохода сотрудников.
Пример файла:
Иванов 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))
20 changes: 20 additions & 0 deletions task-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Задание:
Создать (не программно) текстовый файл со следующим содержимым:
One — 1
Two — 2
Three — 3
Four — 4
Необходимо написать программу, открывающую файл на чтение и считывающую построчно данные.
При этом английские числительные должны заменяться на русские.
Новый блок строк должен записываться в новый текстовый файл.
"""


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)
18 changes: 18 additions & 0 deletions task-5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Задание:
Создать (программно) текстовый файл, записать в него программно набор чисел, разделенных пробелами.
Программа должна подсчитывать сумму чисел в файле и выводить ее на экран.
"""

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))
36 changes: 36 additions & 0 deletions task-6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Задание:
Необходимо создать (не программно) текстовый файл, где каждая строка описывает учебный предмет и наличие лекционных,
практических и лабораторных занятий по этому предмету и их количество.
Важно, чтобы для каждого предмета не обязательно были все типы занятий. Сформировать словарь,
содержащий название предмета и общее количество занятий по нему. Вывести словарь на экран.
Примеры строк файла: Информатика: 100(л) 50(пр) 20(лаб).
Физика: 30(л) — 10(лаб)
Физкультура: — 30(пр) —
Пример словаря: {“Информатика”: 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)
3 changes: 3 additions & 0 deletions task-6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Информатика: 100(л) 50(пр) 20(лаб).
Физика: 30(л) — 10(лаб)
Физкультура: — 30(пр) —
15 changes: 15 additions & 0 deletions task-7.py
Original file line number Diff line number Diff line change
@@ -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}]
Подсказка: использовать менеджер контекста.
"""