From bfff08633662617154478cec295ce8f8790fbe9e Mon Sep 17 00:00:00 2001 From: "merant88@mail.ru" Date: Mon, 14 Sep 2020 22:32:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=97=20=D0=BA=205=20=D1=83=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- #1.py | 7 +++++++ #2.py | 5 +++++ #3.py | 16 ++++++++++++++++ #4.py | 9 +++++++++ #5.py | 8 ++++++++ #6.py | 14 ++++++++++++++ #7.py | 17 +++++++++++++++++ text1.txt | 4 ++++ text2.txt | 3 +++ text3.txt | 3 +++ text4.txt | 4 ++++ text4_1.txt | 4 ++++ text5.txt | 1 + text6.txt | 3 +++ text7.json | 1 + text7.txt | 3 +++ 16 files changed, 102 insertions(+) create mode 100644 #1.py create mode 100644 #2.py create mode 100644 #3.py create mode 100644 #4.py create mode 100644 #5.py create mode 100644 #6.py create mode 100644 #7.py create mode 100644 text1.txt create mode 100644 text2.txt create mode 100644 text3.txt create mode 100644 text4.txt create mode 100644 text4_1.txt create mode 100644 text5.txt create mode 100644 text6.txt create mode 100644 text7.json create mode 100644 text7.txt diff --git a/#1.py b/#1.py new file mode 100644 index 0000000..41e0699 --- /dev/null +++ b/#1.py @@ -0,0 +1,7 @@ +with open('text1.txt', mode='w') as write_dt: + data = input() + while data != '': + write_dt.write(f'{data}\n') + data = input() + + diff --git a/#2.py b/#2.py new file mode 100644 index 0000000..a6a602e --- /dev/null +++ b/#2.py @@ -0,0 +1,5 @@ +with open('text2.txt', 'r') as txt: + string = 1 + for line in txt: + print(f'количество слов в строке {string} - {len(line.split())}') + string += 1 diff --git a/#3.py b/#3.py new file mode 100644 index 0000000..22c8f1a --- /dev/null +++ b/#3.py @@ -0,0 +1,16 @@ +with open('text3.txt', 'r', encoding='UTF-8') as txt: + average = 0 + count = 0 + for line in txt: + try: + salary = int(line.split(' - ')[1]) + if salary < 20000: + print(line, end='') + average += salary + count += 1 + except ValueError: + print('В файле обнаружена ошибка ввода заработной платы!') + except IndexError: + break + print(f'Средняя заработанная плата {average/count:.2f}') + diff --git a/#4.py b/#4.py new file mode 100644 index 0000000..bd80c06 --- /dev/null +++ b/#4.py @@ -0,0 +1,9 @@ +numbers = {'One': 'один', 'Two': 'два', 'Three': 'три', 'Four': 'четыре'} +with open('text4.txt', 'r', encoding='UTF-8') as txt1: + with open('text4_1.txt', 'w', encoding='UTF-8') as txt2: + for line in txt1: + x = line.split(" — ") + try: + txt2.write(f'{numbers[x[0]]} — {x[1]}') + except KeyError: + print('В исходном файле обнаружена ошибка соответствия!') diff --git a/#5.py b/#5.py new file mode 100644 index 0000000..d99c671 --- /dev/null +++ b/#5.py @@ -0,0 +1,8 @@ +from random import randint + + +with open('text5.txt', 'w', encoding='UTF-8') as txt: + for i in range(5): + txt.write(f'{str(randint(1, 100))} ') +with open('text5.txt', 'r', encoding='UTF-8') as txt: + print(sum(map(int, txt.readline().split()))) diff --git a/#6.py b/#6.py new file mode 100644 index 0000000..9b25a64 --- /dev/null +++ b/#6.py @@ -0,0 +1,14 @@ +from itertools import cycle + + +dict = {} +with open('text6.txt', 'r', encoding='UTF-8') as txt: + for line in txt: + subject = ''.join(line.split()[:1])[:-1] + sum = 0 + for a, n in zip(line.split()[1:], cycle([3, 4, 5])): + if a == '—': + continue + sum += int(a[:-n]) + dict[subject] = sum +print(dict) \ No newline at end of file diff --git a/#7.py b/#7.py new file mode 100644 index 0000000..d53cb2d --- /dev/null +++ b/#7.py @@ -0,0 +1,17 @@ +import json + +dict_prof = {} +dict_aver = {} +with open('text7.txt', 'r', encoding='UTF-8') as txt: + count = 0 + suma = 0 + for line in txt: + name, ownership, income, costs = line.split() + profit = int(income) - int(costs) + dict_prof[name] = profit + suma += profit + count += 1 + dict_aver['average_profit'] = suma/count +lists = [dict_prof, dict_aver] +with open("text7.json", "w") as txt: + json.dump(lists, txt) diff --git a/text1.txt b/text1.txt new file mode 100644 index 0000000..d55fca3 --- /dev/null +++ b/text1.txt @@ -0,0 +1,4 @@ +sf +324 +shrt +44444 diff --git a/text2.txt b/text2.txt new file mode 100644 index 0000000..49c22c2 --- /dev/null +++ b/text2.txt @@ -0,0 +1,3 @@ +fefef sfefsf +sdfsf jsdkfjsdf jsfkdf +sdfj \ No newline at end of file diff --git a/text3.txt b/text3.txt new file mode 100644 index 0000000..ba301d9 --- /dev/null +++ b/text3.txt @@ -0,0 +1,3 @@ +Иванов - 20000 +Петров - 10000 +Сидоров - 30000 \ No newline at end of file diff --git a/text4.txt b/text4.txt new file mode 100644 index 0000000..a13d26b --- /dev/null +++ b/text4.txt @@ -0,0 +1,4 @@ +One — 1 +Two — 2 +Three — 3 +Four — 4 diff --git a/text4_1.txt b/text4_1.txt new file mode 100644 index 0000000..ad1476d --- /dev/null +++ b/text4_1.txt @@ -0,0 +1,4 @@ +один — 1 +два — 2 +три — 3 +четыре — 4 diff --git a/text5.txt b/text5.txt new file mode 100644 index 0000000..b93810d --- /dev/null +++ b/text5.txt @@ -0,0 +1 @@ +58 64 37 84 66 \ No newline at end of file diff --git a/text6.txt b/text6.txt new file mode 100644 index 0000000..a349890 --- /dev/null +++ b/text6.txt @@ -0,0 +1,3 @@ +Информатика: 100(л) 50(пр) 20(лаб) +Физика: 30(л) — 10(лаб) +Физкультура: — 30(пр) — \ No newline at end of file diff --git a/text7.json b/text7.json new file mode 100644 index 0000000..3b1640a --- /dev/null +++ b/text7.json @@ -0,0 +1 @@ +[{"firm_1": 5500, "firm_2": 9400, "firm_3": -10000}, {"average_profit": 1633.3333333333333}] \ No newline at end of file diff --git a/text7.txt b/text7.txt new file mode 100644 index 0000000..dd23d5d --- /dev/null +++ b/text7.txt @@ -0,0 +1,3 @@ +firm_1 ООО 10500 5000 +firm_2 ОАО 10000 600 +firm_3 ЗАО 20000 30000 \ No newline at end of file