From f49450604db7406830fc4d561ceacd3716ff9e4d Mon Sep 17 00:00:00 2001 From: "Serebryakov.AO" Date: Fri, 16 Apr 2021 01:27:05 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=204-=D0=B3=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.txt | 7 +++++++ fortask4.txt | 4 ++++ nums.txt | 1 + subjects.txt | 3 +++ task1.py | 12 ++++++++++++ task2.py | 8 ++++++++ task3.py | 16 ++++++++++++++++ task4.py | 24 ++++++++++++++++++++++++ task5.py | 12 ++++++++++++ task6.py | 24 ++++++++++++++++++++++++ workers.txt | 5 +++++ 11 files changed, 116 insertions(+) create mode 100644 data.txt create mode 100644 fortask4.txt create mode 100644 nums.txt create mode 100644 subjects.txt create mode 100644 task1.py create mode 100644 task2.py create mode 100644 task3.py create mode 100644 task4.py create mode 100644 task5.py create mode 100644 task6.py create mode 100644 workers.txt diff --git a/data.txt b/data.txt new file mode 100644 index 0000000..36dcf7d --- /dev/null +++ b/data.txt @@ -0,0 +1,7 @@ +001 +02 +3 0 +40 +5000 +61 xxxx rrrrrrr 0 +7 diff --git a/fortask4.txt b/fortask4.txt new file mode 100644 index 0000000..48de98b --- /dev/null +++ b/fortask4.txt @@ -0,0 +1,4 @@ +One - 1 +Two - 2 +Three - 3 +Four - 4 \ No newline at end of file diff --git a/nums.txt b/nums.txt new file mode 100644 index 0000000..8de6cfe --- /dev/null +++ b/nums.txt @@ -0,0 +1 @@ +0 75 80 54 31 28 89 14 72 43 94 71 34 6 86 88 66 57 96 22 \ No newline at end of file diff --git a/subjects.txt b/subjects.txt new file mode 100644 index 0000000..1d551ed --- /dev/null +++ b/subjects.txt @@ -0,0 +1,3 @@ +: 100() 50() 20(). +: 30() 10() +: 30() \ No newline at end of file diff --git a/task1.py b/task1.py new file mode 100644 index 0000000..697223e --- /dev/null +++ b/task1.py @@ -0,0 +1,12 @@ +print('Запиши строки в файл, используй пробел для выхода:') +my_rows = [] +while True: + new_row = input() + if new_row == ' ': + file = open('data.txt', 'w') + file.writelines(my_rows) + file.close() + print('Я все записал!') + break + my_rows.append(new_row+'\n') + diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..1e0e376 --- /dev/null +++ b/task2.py @@ -0,0 +1,8 @@ +with open('data.txt') as file: + rows = file.readlines() +print(f'Всего {len(rows)} строк') +i = 0 +for string in rows: + words = string.split() + i += 1 + print(f'в {i} строке количество строк = {len(words)} ') diff --git a/task3.py b/task3.py new file mode 100644 index 0000000..8637664 --- /dev/null +++ b/task3.py @@ -0,0 +1,16 @@ +with open('workers.txt') as file: + rows = file.readlines() +lowers = [] +oklads = [] +for row in rows: + name, oklad = row.split() + oklad = int(oklad) + oklads.append(oklad) + if int(oklad) < 20000: + lowers.append(name) +print('У сотрудников', end=': ') +for lower in lowers: + print(lower, sep=', ', end=', ') +print('оклад меньше 20000') +avg = sum(oklads)/len(oklads) +print(f'средний оклад {round(avg,2)}') \ No newline at end of file diff --git a/task4.py b/task4.py new file mode 100644 index 0000000..fdd3ea0 --- /dev/null +++ b/task4.py @@ -0,0 +1,24 @@ +def to_dict(input_string): + slovar = { + "Zero": "Ноль", + "One": "Один", + "Two": "Два", + "Three": "Три", + "Four": "Четыре", + "Five": "Пять", + "Six": "Шесть", + "Seven": "Семь", + "Eight": "Восемь", + "Nine": "Девять" + } + one_row = input_string.split(' - ') + one_row[0] = slovar[one_row[0]] + return ' - '.join(one_row) + +with open('fortask4.txt') as file: + rows = file.readlines() + +rows = list(map(to_dict, rows)) +if(rows): + with open("res-task4.txt", "w") as f_obj: + print(''.join(rows), file=f_obj) diff --git a/task5.py b/task5.py new file mode 100644 index 0000000..3b4ca7a --- /dev/null +++ b/task5.py @@ -0,0 +1,12 @@ +import random +my_list = [random.randint(0, 100) for _ in range(20)] +with open('nums.txt', 'w') as file: + if file.write(' '.join(str(x) for x in my_list)): + print('Записано!') + +with open('nums.txt') as file: + rows = file.readlines() +for numbers in rows: + nums = [int(el) for el in numbers.split()] + break +print(f'Сумма {sum(nums)}') diff --git a/task6.py b/task6.py new file mode 100644 index 0000000..5b63f29 --- /dev/null +++ b/task6.py @@ -0,0 +1,24 @@ +def only_nums(string): + num_list = [] + num = '' + for char in string: + if char.isdigit(): + num = num + char + else: + if num != '': + num_list.append(int(num)) + num = '' + if num != '': + num_list.append(int(num)) + return sum(num_list) + + +with open('subjects.txt') as file: + rows = file.readlines() +new_dict = {} + +for row in rows: + ar_row = row.split(':') + new_dict[ar_row[0]] = only_nums(ar_row[1]) + +print(new_dict) diff --git a/workers.txt b/workers.txt new file mode 100644 index 0000000..48efdf7 --- /dev/null +++ b/workers.txt @@ -0,0 +1,5 @@ +Ivanov 80000 +Petrov 95000 +Sidorov 105000 +Silver 250000 +Brown 19500 From 19da40379eea8b190c9c2acff7a86919f236bc57 Mon Sep 17 00:00:00 2001 From: "Serebryakov.AO" Date: Fri, 16 Apr 2021 07:00:01 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=205-=D0=B3=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F,=207=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- companies.txt | 4 ++++ task7.py | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 companies.txt create mode 100644 task7.py diff --git a/companies.txt b/companies.txt new file mode 100644 index 0000000..6ae4cb8 --- /dev/null +++ b/companies.txt @@ -0,0 +1,4 @@ + 2000 3000 + 6000 1000 + 60000 7000 + 200 150 \ No newline at end of file diff --git a/task7.py b/task7.py new file mode 100644 index 0000000..aa8a701 --- /dev/null +++ b/task7.py @@ -0,0 +1,27 @@ +import json +profit_dict = {} +pr = {} +profit = 0 +profit_average = 0 +i = 0 +with open('companies.txt', 'r') as file: + for line in file: + company, form, income, outlay = line.split() + company_name = form + ' ' + company + profit_dict[company_name] = int(income) - int(outlay) + if profit_dict.setdefault(company_name) >= 0: + profit = profit + profit_dict.setdefault(company_name) + i += 1 + if i != 0: + profit_average = profit / i + print(f'Средняя прибыль - {profit_average:.2f}') + else: + print(f'Все работают в убыток') + pr = {'средняя прибыль': round(profit_average)} + profit_dict.update(pr) + print(f'Прибыль по компаниям - {profit_dict}') + +with open('companies.json', 'w') as write_js: + json.dump(profit_dict, write_js) + js_file = json.dumps(profit_dict) + print(f'записано в файл.')