Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions companies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
������� ��� 2000 3000
��������� ��� 6000 1000
������� ��� 60000 7000
���������� �� 200 150
7 changes: 7 additions & 0 deletions data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
001
02
3 0
40
5000
61 xxxx rrrrrrr 0
7
4 changes: 4 additions & 0 deletions fortask4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
One - 1
Two - 2
Three - 3
Four - 4
1 change: 1 addition & 0 deletions nums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 75 80 54 31 28 89 14 72 43 94 71 34 6 86 88 66 57 96 22
3 changes: 3 additions & 0 deletions subjects.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
�����������: 100(�) 50(��) 20(���).
������: 30(�) � 10(���)
�����������: � 30(��)
12 changes: 12 additions & 0 deletions task1.py
Original file line number Diff line number Diff line change
@@ -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')

8 changes: 8 additions & 0 deletions task2.py
Original file line number Diff line number Diff line change
@@ -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)} ')
16 changes: 16 additions & 0 deletions task3.py
Original file line number Diff line number Diff line change
@@ -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)}')
24 changes: 24 additions & 0 deletions task4.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions task5.py
Original file line number Diff line number Diff line change
@@ -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)}')
24 changes: 24 additions & 0 deletions task6.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions task7.py
Original file line number Diff line number Diff line change
@@ -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'записано в файл.')
5 changes: 5 additions & 0 deletions workers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Ivanov 80000
Petrov 95000
Sidorov 105000
Silver 250000
Brown 19500