From 7aed3bff04174e43aea97ccf07ccd6db29488f2e Mon Sep 17 00:00:00 2001 From: "d.zashivalov" Date: Sat, 16 Apr 2022 14:56:26 +0300 Subject: [PATCH] Lesson_5 --- lesson_5/5-1.py | 6 ++++++ lesson_5/5-2.py | 4 ++++ lesson_5/5-3.py | 9 +++++++++ lesson_5/5-4.py | 5 +++++ lesson_5/5-5.py | 15 +++++++++++++++ lesson_5/5-6.py | 2 ++ lesson_5/5-7.py | 28 ++++++++++++++++++++++++++++ lesson_5/File4_ru.txt | 4 ++++ lesson_5/File5_1.txt | 4 ++++ lesson_5/file5_5.txt | 1 + lesson_5/file_7.json | 1 + lesson_5/text_3.txt | 10 ++++++++++ lesson_5/text_4.txt | 4 ++++ lesson_5/text_6.txt | 7 +++++++ lesson_5/text_7.txt | 5 +++++ 15 files changed, 105 insertions(+) create mode 100644 lesson_5/5-1.py create mode 100644 lesson_5/5-2.py create mode 100644 lesson_5/5-3.py create mode 100644 lesson_5/5-4.py create mode 100644 lesson_5/5-5.py create mode 100644 lesson_5/5-6.py create mode 100644 lesson_5/5-7.py create mode 100644 lesson_5/File4_ru.txt create mode 100644 lesson_5/File5_1.txt create mode 100644 lesson_5/file5_5.txt create mode 100644 lesson_5/file_7.json create mode 100644 lesson_5/text_3.txt create mode 100644 lesson_5/text_4.txt create mode 100644 lesson_5/text_6.txt create mode 100644 lesson_5/text_7.txt diff --git a/lesson_5/5-1.py b/lesson_5/5-1.py new file mode 100644 index 0000000..545c1e3 --- /dev/null +++ b/lesson_5/5-1.py @@ -0,0 +1,6 @@ +with open('File5_1.txt', 'w', encoding='utf-8') as perf: + while True: + line = input('введите текст, для окончания ввода оставте пустую строку: ') + if not line: + break + print(line, file=perf) \ No newline at end of file diff --git a/lesson_5/5-2.py b/lesson_5/5-2.py new file mode 100644 index 0000000..c4b46ce --- /dev/null +++ b/lesson_5/5-2.py @@ -0,0 +1,4 @@ +with open('File5_1.txt', 'r', encoding='utf-8') as perf: + res = [f'{line}. {count.strip()} - {len(count.split())} слова' + for line, count in enumerate(perf, 1)] + print(*res, f'Всего строк - {len(res)}.', sep='\n') \ No newline at end of file diff --git a/lesson_5/5-3.py b/lesson_5/5-3.py new file mode 100644 index 0000000..65ce208 --- /dev/null +++ b/lesson_5/5-3.py @@ -0,0 +1,9 @@ +with open('text_3.txt', 'r', encoding='utf-8') as perf: + creeps = {} + for line in perf: + creeps[line.split()[0]] = float(line.split()[1]) + print('менее 20к получают:') +for name, creep in creeps.items(): + if creep < 20000: + print(name) +print(f'средняя з\п равна {sum(creeps.values()) / len(creeps)}') \ No newline at end of file diff --git a/lesson_5/5-4.py b/lesson_5/5-4.py new file mode 100644 index 0000000..b84d315 --- /dev/null +++ b/lesson_5/5-4.py @@ -0,0 +1,5 @@ +rus = {'One': 'Один', 'Two': 'Два', 'Three': 'Три', 'Four': 'Четыре'} + +with open('File4_ru.txt', 'w', encoding='utf-8') as new_perf: + with open('text_4.txt', encoding='utf-8') as perf: + new_perf.writelines([line.replace(line.split()[0], rus.get(line.split()[0])) for line in perf]) \ No newline at end of file diff --git a/lesson_5/5-5.py b/lesson_5/5-5.py new file mode 100644 index 0000000..60bcae3 --- /dev/null +++ b/lesson_5/5-5.py @@ -0,0 +1,15 @@ +def summary(): + try: + with open('file5_5.txt', 'w+') as perf: + line = input('Введите цифры через пробел \n') + perf.writelines(line) + my_numbers = line.split() + + print(sum(map(int, my_numbers))) + except IOError: + print('Ошибка в файле') + except ValueError: + print('Некорректные данные!') + + +summary() \ No newline at end of file diff --git a/lesson_5/5-6.py b/lesson_5/5-6.py new file mode 100644 index 0000000..35d09a4 --- /dev/null +++ b/lesson_5/5-6.py @@ -0,0 +1,2 @@ +with open('text_6.txt', 'r', encoding='utf-8') as perf: + print({string.split(':')[0]: sum([int(s[:s.index('(')]) for s in string.split() if '(' in s]) for string in perf}) diff --git a/lesson_5/5-7.py b/lesson_5/5-7.py new file mode 100644 index 0000000..23ab369 --- /dev/null +++ b/lesson_5/5-7.py @@ -0,0 +1,28 @@ +import json +profit = {} +pr = {} +prof = 0 +prof_aver = 0 +i = 0 +with open('text_7.txt', 'r') as file: + for line in file: + name, firm, earning, damage = line.split() + profit[name] = int(earning) - int(damage) + if profit.setdefault(name) >= 0: + prof = prof + profit.setdefault(name) + i += 1 + if i != 0: + prof_aver = prof / i + print(f'Прибыль средняя - {prof_aver:.2f}') + else: + print(f'Прибыль средняя - отсутсвует. Все работают в убыток') + pr = {'средняя прибыль': round(prof_aver)} + profit.update(pr) + print(f'Прибыль каждой компании - {profit}') + +with open('file_7.json', 'w') as write_js: + json.dump(profit, write_js) + + js_str = json.dumps(profit) + print(f'Создан файл с расширением json со следующим содержимым: \n ' + f' {js_str}') \ No newline at end of file diff --git a/lesson_5/File4_ru.txt b/lesson_5/File4_ru.txt new file mode 100644 index 0000000..3fc3169 --- /dev/null +++ b/lesson_5/File4_ru.txt @@ -0,0 +1,4 @@ +Один - 1 +Два - 2 +Три - 3 +Четыре - 4 \ No newline at end of file diff --git a/lesson_5/File5_1.txt b/lesson_5/File5_1.txt new file mode 100644 index 0000000..73cb74c --- /dev/null +++ b/lesson_5/File5_1.txt @@ -0,0 +1,4 @@ +line 1 +line 2 +zdarova kak dela +line 3 \ No newline at end of file diff --git a/lesson_5/file5_5.txt b/lesson_5/file5_5.txt new file mode 100644 index 0000000..7b91a34 --- /dev/null +++ b/lesson_5/file5_5.txt @@ -0,0 +1 @@ +65 65 789 45 13 5 \ No newline at end of file diff --git a/lesson_5/file_7.json b/lesson_5/file_7.json new file mode 100644 index 0000000..a5cb017 --- /dev/null +++ b/lesson_5/file_7.json @@ -0,0 +1 @@ +{"Brooms": 2000000, "Tandoor": -635000, "Honey-cake": 4795000, "Matrioshka": 4259000, "\u0421\u043a\u0430\u0437\u043a\u0430": 5500000, "\u0441\u0440\u0435\u0434\u043d\u044f\u044f \u043f\u0440\u0438\u0431\u044b\u043b\u044c": 4138500} diff --git a/lesson_5/text_3.txt b/lesson_5/text_3.txt new file mode 100644 index 0000000..9edd785 --- /dev/null +++ b/lesson_5/text_3.txt @@ -0,0 +1,10 @@ +Иванов 10000.0 +Петров 15000.0 +Сидоров 25000.1 +Иванова 15000.7 +Петрова 19000.9 +Сидорова 26000.1 +Октябрьский 30000.5 +Петровский 26000.4 +Знаменский 12000.0 +Корецкий 31000.9 \ No newline at end of file diff --git a/lesson_5/text_4.txt b/lesson_5/text_4.txt new file mode 100644 index 0000000..48de98b --- /dev/null +++ b/lesson_5/text_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/text_6.txt b/lesson_5/text_6.txt new file mode 100644 index 0000000..65f0079 --- /dev/null +++ b/lesson_5/text_6.txt @@ -0,0 +1,7 @@ +Fizra: - 30(пр) - +Math: 10(л) 50(пр) - +History: 50(л) - - +Physics: 70(л) 20(пр) 18(лаб) +Informatics: 40(л) 12(пр) 20(лаб) +Literature: 10(л) - 8(лаб) +Russian: - - 90(лаб) \ No newline at end of file diff --git a/lesson_5/text_7.txt b/lesson_5/text_7.txt new file mode 100644 index 0000000..f2bacc1 --- /dev/null +++ b/lesson_5/text_7.txt @@ -0,0 +1,5 @@ +Brooms ПАО 2500000 500000 +Tandoor АО 1245000 1880000 +Honey-cake ЗАО 5250000 455000 +Matrioshka OOO 4770000 511000 +Сказка ИП 10500000 5000000 \ No newline at end of file