diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d56657a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2572635 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/.idea/\320\236\321\201\320\275\320\276\320\262\321\213.iml" "b/.idea/\320\236\321\201\320\275\320\276\320\262\321\213.iml" new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ "b/.idea/\320\236\321\201\320\275\320\276\320\262\321\213.iml" @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lesson_5/L5_T4.txt b/Lesson_5/L5_T4.txt new file mode 100644 index 0000000..48de98b --- /dev/null +++ b/Lesson_5/L5_T4.txt @@ -0,0 +1,4 @@ +One - 1 +Two - 2 +Three - 3 +Four - 4 \ No newline at end of file diff --git a/Lesson_5/L5_T4_1.txt b/Lesson_5/L5_T4_1.txt new file mode 100644 index 0000000..8d7d0ba --- /dev/null +++ b/Lesson_5/L5_T4_1.txt @@ -0,0 +1,4 @@ +Один- 1 +Два- 2 +Три- 3 +Четыре- 4 \ No newline at end of file diff --git a/Lesson_5/L5_T5.txt b/Lesson_5/L5_T5.txt new file mode 100644 index 0000000..a498169 --- /dev/null +++ b/Lesson_5/L5_T5.txt @@ -0,0 +1 @@ +3 33 \ No newline at end of file diff --git a/Lesson_5/L5_T6.py b/Lesson_5/L5_T6.py new file mode 100644 index 0000000..9568cde --- /dev/null +++ b/Lesson_5/L5_T6.py @@ -0,0 +1,58 @@ +# Необходимо создать (не программно) текстовый файл, +# где каждая строка описывает учебный предмет и наличие лекционных, практических и лабораторных занятий +# по этому предмету и их количество. +# Важно, чтобы для каждого предмета не обязательно были все типы занятий. +# Сформировать словарь, содержащий название предмета и общее количество занятий по нему. +# Вывести словарь на экран. +# Примеры строк файла: +# Информатика: 100(л) 50(пр) 20(лаб). +# Физика: 30(л) — 10(лаб) +# Физкультура: — 30(пр) — +# +# Пример словаря: +# {“Информатика”: 170, “Физика”: 40, “Физкультура”: 30} + +d = {} +with open('Les5_T6.txt', 'r', encoding='UTF-8') as f_obj: + while True: + s=0 + f_obj_line=f_obj.readline() + if not f_obj_line: + break + key_value = f_obj_line.split(" ") + for i in key_value[1:]: + j='' + for x in range(len(i)): + if i[x].isdigit(): + j+=i[x] + if j != '': + s+= int(j) + d[key_value[0][0:-1]] = s +print(d) + + + + # for line in f_obj_line: + # key_value = line.split(" ") + # value = 0 + # for i in d: + # list=d(i) + # if i.isdigit(): + # value+=i + # else: + # break + # for j in sum_value: + # s_value+= sum_value(j) + # print(s_value) + + + + + + + + + + + + diff --git a/Lesson_5/L5_T7.py b/Lesson_5/L5_T7.py new file mode 100644 index 0000000..4069255 --- /dev/null +++ b/Lesson_5/L5_T7.py @@ -0,0 +1,34 @@ +# 7. Создать (не программно) текстовый файл, в котором каждая строка должна содержать данные о фирме: +# название, форма собственности, выручка, издержки. +# Пример строки файла: firm_1 ООО 10000 5000. +# Необходимо построчно прочитать файл, вычислить прибыль каждой компании, а также среднюю прибыль. +# Если фирма получила убытки, в расчет средней прибыли ее не включать. +# Далее реализовать список. Он должен содержать словарь с фирмами и их прибылями, а также словарь со средней прибылью. Если фирма получила убытки, также добавить ее в словарь (со значением убытков). +# Пример списка: [{“firm_1”: 5000, “firm_2”: 3000, “firm_3”: 1000}, {“average_profit”: 2000}]. +# Итоговый список сохранить в виде json-объекта в соответствующий файл. +# Пример json-объекта: +# [{"firm_1": 5000, "firm_2": 3000, "firm_3": 1000}, {"average_profit": 2000}] +# +# Подсказка: использовать менеджеры контекста. + +import json + +list1={} +med_prft={} +rev=0 +costs=0 +with open('Les5_t7.txt','r', encoding='UTF-8') as f_obj: + while True: + my_file = f_obj.readline().split() + if not my_file: + break + prft = int(my_file[2]) - int(my_file[3]) + if prft>0: + rev+=1 + costs += prft + list1[my_file[0]]=prft +med_prft=costs/rev +result = [list1, med_prft] +print(result) +with open("result.json", 'w', encoding='utf-8') as f_obj: + json.dump(result, f_obj) diff --git a/Lesson_5/L5_t3.txt b/Lesson_5/L5_t3.txt new file mode 100644 index 0000000..65e23cf --- /dev/null +++ b/Lesson_5/L5_t3.txt @@ -0,0 +1,10 @@ +Иванов 15245.23 +Петров 56325.35 +Чирков 95354.23 +Сидоров 56353.22 +Задорнов 18321.44 +Алексеев 62354.12 +Сергеев 35543.32 +Александров 35435.24 +Владимиров 36533.24 +Смирнов 16355.6 diff --git a/Lesson_5/Les5_T5.py b/Lesson_5/Les5_T5.py new file mode 100644 index 0000000..d5f1eff --- /dev/null +++ b/Lesson_5/Les5_T5.py @@ -0,0 +1,18 @@ +# Создать (программно) текстовый файл, записать в него программно набор чисел, +# разделенных пробелами. Программа должна подсчитывать сумму чисел в файле и +# выводить ее на экран. + +def num(string): + total = 0 + for number in string: + total += int(number) + return total +my_file = open('L5_T5.txt', 'w+') +my_list = input("Введите числа через пробел:") +my_file.write(my_list) +my_file.seek(0) +my_list1 = my_file.read() +my_list2=my_list1.split(' ') +print(num(my_list2)) + +my_file.close() diff --git a/Lesson_5/Les5_T6.txt b/Lesson_5/Les5_T6.txt new file mode 100644 index 0000000..b2b260e --- /dev/null +++ b/Lesson_5/Les5_T6.txt @@ -0,0 +1,3 @@ +Информатика: 100(л) 70(пр) 40(лаб). +Физика: 70(л) — 90(лаб) +Физкультура: — 40(пр) — \ No newline at end of file diff --git a/Lesson_5/Les5_Task1.py b/Lesson_5/Les5_Task1.py new file mode 100644 index 0000000..5f5382d --- /dev/null +++ b/Lesson_5/Les5_Task1.py @@ -0,0 +1,8 @@ + +with open("text.txt", 'r') as file_obj: + content = file_obj.read() + end = () + print(content) + for i in content: + print(i) + diff --git a/Lesson_5/Les5_Task2.py b/Lesson_5/Les5_Task2.py new file mode 100644 index 0000000..4053b2b --- /dev/null +++ b/Lesson_5/Les5_Task2.py @@ -0,0 +1,11 @@ + +with open("text.txt", 'r') as file_obj: + content = (file_obj.readlines()) + print('В файле Text',len(content),'строк') + for i in range(len(content)): + content_1 = content[i].split() + print('В', i + 1,'строке', len(content_1), 'слов(а)') + print(content) + + + diff --git a/Lesson_5/Les5_Task3.py b/Lesson_5/Les5_Task3.py new file mode 100644 index 0000000..979ecb7 --- /dev/null +++ b/Lesson_5/Les5_Task3.py @@ -0,0 +1,18 @@ +with open('L5_t3.txt', 'r', encoding='UTF-8') as my_file: + i = 0 + s = 0 + print('Список сотрудников с окладом менее 20000:') + while True: + my_list = my_file.readline() + if not my_list: + break + if float(my_list.split(' ')[1]) < 20000: + print(my_list.split(' ')[0]) + s += float(my_list.split(' ')[1]) + i += 1 + + print('Средняя заработная плата сотрудников:', s/i) + + + + diff --git a/Lesson_5/Les5_Task4.py b/Lesson_5/Les5_Task4.py new file mode 100644 index 0000000..5585273 --- /dev/null +++ b/Lesson_5/Les5_Task4.py @@ -0,0 +1,14 @@ +with open('L5_T4.txt', encoding='UTF-8') as f_obj: + for line in f_obj: + print(line) +rus_dict = {'One' : 'Один', 'Two' : 'Два', 'Three' : 'Три', 'Four' : 'Четыре'} +new_dict = [] +with open('L5_T4.txt') as f_obj: + for i in f_obj: + i = i.split(' ', 1) + new_dict.append(rus_dict[i[0]] + i[1]) + print(new_dict) + +with open('L5_T4_1.txt', 'w', encoding='UTF-8') as file_obj_1: + file_obj_1.writelines(new_dict) + diff --git a/Lesson_5/Les5_t7.txt b/Lesson_5/Les5_t7.txt new file mode 100644 index 0000000..f0adb3b --- /dev/null +++ b/Lesson_5/Les5_t7.txt @@ -0,0 +1,3 @@ +firm_1 OOO 10000 4000 +firm_2 OOO 30000 200000 +firm_3 OOO 20000 50000 diff --git a/Lesson_5/Text.txt b/Lesson_5/Text.txt new file mode 100644 index 0000000..60ca598 --- /dev/null +++ b/Lesson_5/Text.txt @@ -0,0 +1,7 @@ +Hello! +My name is Olesia +I am studying at the online university "Geek Brains" +bla-bla +bla bla bla +bla +bla-bla, bla, bla diff --git a/Lesson_5/file_4_new.txt b/Lesson_5/file_4_new.txt new file mode 100644 index 0000000..9329294 --- /dev/null +++ b/Lesson_5/file_4_new.txt @@ -0,0 +1,4 @@ +���� - 1 +��� - 2 +��� - 3 +������ - 4 \ No newline at end of file diff --git a/Lesson_5/result.json b/Lesson_5/result.json new file mode 100644 index 0000000..aed233d --- /dev/null +++ b/Lesson_5/result.json @@ -0,0 +1 @@ +[{"firm_1": 6000, "firm_2": -170000, "firm_3": -30000}, 6000.0] \ No newline at end of file