diff --git a/README.md b/README.md deleted file mode 100644 index 68abb7b..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# GU_BigData_1795 \ No newline at end of file diff --git a/lesson5/ex2.txt b/lesson5/ex2.txt new file mode 100644 index 0000000..46a4915 --- /dev/null +++ b/lesson5/ex2.txt @@ -0,0 +1,3 @@ +do did done +1 2 3 +Привет \ No newline at end of file diff --git a/lesson5/ex3.txt b/lesson5/ex3.txt new file mode 100644 index 0000000..6e04d5f --- /dev/null +++ b/lesson5/ex3.txt @@ -0,0 +1,17 @@ +Несветова 150000 +Адамов 98687 +Денисов 231185 +Рюрикович 127080 +Робертс 1000000 +Монтана 398400 +Тодд 580900 +О'Клай 497568 +Королев 352698 +Руккулус 19500 +Катрин 18668 +Агеев 3140329 +Басов 2000288 +Макушин 1400356 +Годес 190543 +Бирюков 32999 +Пискарев 400650 \ No newline at end of file diff --git a/lesson5/ex4.txt b/lesson5/ex4.txt new file mode 100644 index 0000000..48de98b --- /dev/null +++ b/lesson5/ex4.txt @@ -0,0 +1,4 @@ +One - 1 +Two - 2 +Three - 3 +Four - 4 \ No newline at end of file diff --git a/lesson5/ex5.txt b/lesson5/ex5.txt new file mode 100644 index 0000000..1d72e45 --- /dev/null +++ b/lesson5/ex5.txt @@ -0,0 +1 @@ +5 0 1 2 3 7 9 5 6 81 4 56 1 \ No newline at end of file diff --git a/lesson5/ex6.txt b/lesson5/ex6.txt new file mode 100644 index 0000000..08ed51e --- /dev/null +++ b/lesson5/ex6.txt @@ -0,0 +1,10 @@ +Матанализ: 16(л) 8(пр) - +Физика: 16(л) 8(пр) 5(лаб) +Теринф: 8(л) 8(пр) 2(лаб) +Английский: - 24(пр) - +Тервер: 16(л) 16(пр) - +Дифуры: 16(л) 16(пр) - +Дискретка: 16(л) 16(пр) - +ОПД: - 8(пр) 1(лаб) +Физра: - - 8(лаб) +ТФКП: 16(лек) - - \ No newline at end of file diff --git a/lesson5/ex7.txt b/lesson5/ex7.txt new file mode 100644 index 0000000..eb0e19b --- /dev/null +++ b/lesson5/ex7.txt @@ -0,0 +1,7 @@ +MosAuto OOO 7545745 3344667 +SeriousBank OAO 4356043809 5495405 +GeneralStatistics OOO 7547547 434244 +WildestNanos OAO 5435954 454598 +NoNamers ZAO 4507497975 0 +Moshpitttt OAO 94594 394293 +Elvirience OAO 3464943080 48545008 \ No newline at end of file diff --git a/lesson5/homework5.py b/lesson5/homework5.py new file mode 100644 index 0000000..1375037 --- /dev/null +++ b/lesson5/homework5.py @@ -0,0 +1,174 @@ +""" +Агеев Георгий BigData 1795 +""" +""" +Не успевал сдать нормальную работу вовремя, поэтому коммитил изменения +Буду очень признателен, если у вас есть возможность оценить последнюю версию, а не первую +""" + + +import json + + +def num1(): + fin = open('ex1.txt', 'w', encoding='UTF-8') + data = input('Введите данные для записи в файл или пустую строку: ') + while data != '': + fin.write(data + '\n') + data = input('Введите данные для записи в файл или пустую строку: ') + fin.close() + + +def num2(lines=0, words=0): + fout = open('ex2.txt', encoding='UTF-8') + for i in fout.readlines(): + print(f"Число слов в строке {lines + 1}: {len(i.split())}") + lines += 1 + print(f'Число строк: {lines}') + fout.close() + + +def num3(i=0, count=0): + with open('ex3.txt', encoding='UTF-8') as fout: + for line in fout: + surname, salary = line.split() + i += int(salary) + if int(salary) < 20000: + print(surname) + count += 1 + print(f'Средняя величина дохода: {int(i / count)}') + + +def num4(i=0): + fout = open('ex4.txt', encoding='UTF-8') + fin = open('ex4_in.txt', 'w', encoding='UTF-8') + my_list = ['Один', 'Два', 'Три', 'Четыре'] + for line in fout: + line = line.split(' - ') + line[0] = my_list[i] + fin.write(' - '.join(line)) + i += 1 + fout.close() + fin.close() + + +def num5(i=0, sum=0): + with open('ex5.txt', 'w+', encoding='UTF - 8') as fin: + fin.write('5 0 1 2 3 7 9 5 6 81 4 56 1') + fin.seek(0) + for i in fin.readline().split(): + sum += int(i) + print(sum) + + +""" +Сначал успел сделать только топорный вариант в рамках заполнения файла, как в примере. +В 6.2 позже описал более универсальное решение +""" + + +def num6(result_dict={}): + with open('ex6.txt', encoding='UTF - 8') as fout: + for line in fout: + line = line.split() + sum = 0 + """ + Разбил строку на слова без пробелов + """ + for i in line: + """ + Каждое слово делю на две части по "(" + Для названия предмета, которое всегда стоит первым элементом в списке, + а так же для случаев, когда стоит прочерк, описываю try - except: + """ + try: + i = i.split('(') + sum += int(i[0]) + except ValueError: + pass + """ + line[0] - первый элемент каждой строки в файле - название предмета + После названия предмета следует ":", поэтому делаю срез строки + """ + unit_dict = {line[0][:-1]: {sum}} + result_dict.update(unit_dict) + print(result_dict) + + +def num6_2(result_dict={}): + with open('ex6.txt', encoding='UTF - 8') as fout: + for line in fout: + line = line.split() + """ + Для каждой строки обнуляю общее число занятий по предмету + """ + sum = 0 + for element in line: + """ + Ищу символы в элементах списка строк, которые на самом деле являются числами + Перед проверкой каждого элемента списка строка пустая + """ + string = '' + for symbol in element: + try: + int(symbol) + string += symbol + except ValueError: + pass + """ + Обработка исключений на случай, + если стоит прочерк (чтобы не int(string), где string = '') + В остальных случаях прибавляю найденное число занятий + """ + try: + sum += int(string) + except ValueError: + pass + unit_dict = {line[0][:-1]: {sum}} + result_dict.update(unit_dict) + print(result_dict) + + +def num7(all_profit=0, count=0, firm_dict={}): + with open('ex7.txt', encoding='UTF - 8') as fout: + for line in fout: + line = line.split() + profit = int(line[2]) - int(line[3]) + if profit > 0: + all_profit += profit + else: + pass + count += 1 + unit_dict = {line[0]: profit} + firm_dict.update(unit_dict) + my_list = [firm_dict, {'Average profit': all_profit / count}] + print(my_list) + """ + json + """ + with open('ex7.json', 'w', encoding='UTF - 8') as fin: + fin.write(json.dumps(my_list)) + + +""" +main(): +""" +q = ' ' +while q != '': + q = input('Введите номер задания или нажмите ENTER: ') + if q == '1': + num1() + elif q == '2': + num2() + elif q == '3': + num3() + elif q == '4': + num4() + elif q == '5': + num5() + elif q == '6': + num6() + elif q == '6.2': + num6_2() + elif q == '7': + num7()