From 7082c85276c118b096f7d306ca7c6300b64bde84 Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Sun, 12 Sep 2021 14:57:49 +0300 Subject: [PATCH 1/9] 1_date_and_time.py Done --- 1_date_and_time.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/1_date_and_time.py b/1_date_and_time.py index e72d76a..76fd11c 100644 --- a/1_date_and_time.py +++ b/1_date_and_time.py @@ -1,3 +1,5 @@ +import locale +from datetime import datetime, timedelta """ Домашнее задание №2 @@ -8,12 +10,21 @@ """ + def print_days(): """ Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + locale.setlocale(locale.LC_ALL, "russian") + date_now = datetime.now() + delta_1 = timedelta(days=1) + date_1 = date_now - delta_1 + print('Вчера: ' + date_1.strftime('%A %d %B %Y')) + print('Сегодня: ' + date_now.strftime('%A %d %B %Y')) + delta_30 = timedelta(days=30) + date_30 = date_now - delta_30 + print('30 дней назад: ' + date_30.strftime('%A %d %B %Y')) def str_2_datetime(date_string): @@ -21,7 +32,9 @@ def str_2_datetime(date_string): Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + date_dt = datetime.strptime(date_string, '%d/%m/%y %H:%M:%S.%f') + return date_dt + if __name__ == "__main__": print_days() From 1a6f7503ace0d861d2af95649354f622b8f03abf Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Mon, 13 Sep 2021 20:44:02 +0300 Subject: [PATCH 2/9] 2_files.py Done --- .idea/.gitignore | 3 +++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/learn-homework-2.iml | 14 ++++++++++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 2_files.py | 11 ++++++++++- referat.txt | 7 +++++++ referat2.txt | 7 +++++++ 9 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/learn-homework-2.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 referat.txt create mode 100644 referat2.txt 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/learn-homework-2.iml b/.idea/learn-homework-2.iml new file mode 100644 index 0000000..0a2ad20 --- /dev/null +++ b/.idea/learn-homework-2.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d1e22ec --- /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..0225a5a --- /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/2_files.py b/2_files.py index 5072b13..310b1be 100644 --- a/2_files.py +++ b/2_files.py @@ -11,12 +11,21 @@ 5. Сохраните результат в файл referat2.txt """ + def main(): """ Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + with open(r'referat.txt', encoding='utf-8') as f: + content = f.read() + string_len = (len(content)) + words_count = content.split() + sign_replace = content.replace('.', '!') + + with open('referat2.txt', 'w', encoding='utf-8') as f: + f.write(sign_replace) + if __name__ == "__main__": main() diff --git a/referat.txt b/referat.txt new file mode 100644 index 0000000..e6e7a0f --- /dev/null +++ b/referat.txt @@ -0,0 +1,7 @@ +Сочинение +Тема: «Экваториальный популяционный индекс: гипотеза и теории» +Ось, после осторожного анализа, аннигилирует неопровержимый экватор. Скиннер, однако, настаивал, что пустое подмножество индивидуально понимает конвергентный гендер. Воспитание притягивает космический предел функции. Функция многих переменных притягивает тропический год. + +Однако, исследователи постоянно сталкиваются с тем, что ригидность многопланово решает первоначальный генезис, день этот пришелся на двадцать шестое число месяца карнея, который у афинян называется метагитнионом. Представляется логичным, что керн ничтожно охватывает возрастной контрпример, так, например, Ричард Бендлер для построения эффективных состояний использовал изменение субмодальностей. Линейное уравнение меняет коллинеарный популяционный индекс в силу которого смешивает субъективное и объективное, переносит свои внутренние побуждения на реальные связи вещей. То, что написано на этой странице неправда! Следовательно: предсознательное продуцирует эффективный диаметp. Эклиптика колеблет контраст. Арифметическая прогрессия недоступно решает межпланетный постулат. + +Представленный контент-анализ является психолингвистическим в своей основе, таким образом гетерогенность непосредственно начинает Юпитер. Определитель системы линейных уравнений допускает индивидуальный автоматизм. Реликтовый ледник, на первый взгляд, просветляет вектор. Лидерство ищет метод последовательных приближений, в полном соответствии с основными законами развития человека. \ No newline at end of file diff --git a/referat2.txt b/referat2.txt new file mode 100644 index 0000000..8da5d4d --- /dev/null +++ b/referat2.txt @@ -0,0 +1,7 @@ +Сочинение +Тема: «Экваториальный популяционный индекс: гипотеза и теории» +Ось, после осторожного анализа, аннигилирует неопровержимый экватор! Скиннер, однако, настаивал, что пустое подмножество индивидуально понимает конвергентный гендер! Воспитание притягивает космический предел функции! Функция многих переменных притягивает тропический год! + +Однако, исследователи постоянно сталкиваются с тем, что ригидность многопланово решает первоначальный генезис, день этот пришелся на двадцать шестое число месяца карнея, который у афинян называется метагитнионом! Представляется логичным, что керн ничтожно охватывает возрастной контрпример, так, например, Ричард Бендлер для построения эффективных состояний использовал изменение субмодальностей! Линейное уравнение меняет коллинеарный популяционный индекс в силу которого смешивает субъективное и объективное, переносит свои внутренние побуждения на реальные связи вещей! То, что написано на этой странице неправда! Следовательно: предсознательное продуцирует эффективный диаметp! Эклиптика колеблет контраст! Арифметическая прогрессия недоступно решает межпланетный постулат! + +Представленный контент-анализ является психолингвистическим в своей основе, таким образом гетерогенность непосредственно начинает Юпитер! Определитель системы линейных уравнений допускает индивидуальный автоматизм! Реликтовый ледник, на первый взгляд, просветляет вектор! Лидерство ищет метод последовательных приближений, в полном соответствии с основными законами развития человека! \ No newline at end of file From 2526bd5c59daef7621a44e2c9d0f96db42d867aa Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Mon, 13 Sep 2021 20:48:40 +0300 Subject: [PATCH 3/9] 2_files.py Done --- 2_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2_files.py b/2_files.py index 310b1be..36eb883 100644 --- a/2_files.py +++ b/2_files.py @@ -20,7 +20,7 @@ def main(): with open(r'referat.txt', encoding='utf-8') as f: content = f.read() string_len = (len(content)) - words_count = content.split() + words_count = len((content.split())) sign_replace = content.replace('.', '!') with open('referat2.txt', 'w', encoding='utf-8') as f: From ea71beba52abce2d65b29eb512df98ab8a253bfa Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Mon, 13 Sep 2021 21:32:32 +0300 Subject: [PATCH 4/9] 3_dict_to_csv.py Done --- 3_dict_to_csv.py | 15 ++++++++++++++- some.csv | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 some.csv diff --git a/3_dict_to_csv.py b/3_dict_to_csv.py index 44d6efb..99e07c6 100644 --- a/3_dict_to_csv.py +++ b/3_dict_to_csv.py @@ -9,13 +9,26 @@ 2. Запишите содержимое списка словарей в файл в формате csv """ +import csv + +list_of_dicts = [{'name': 'Маша', 'age': 25, 'job': 'Scientist'}, + {'name': 'Вася', 'age': 8, 'job': 'Programmer'}, + {'name': 'Дуся', 'age': 18, 'job': 'Small boss'}, + {'name': 'Эдуард', 'age': 48, 'job': 'Big boss'}] + def main(): """ Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + with open('some.csv', 'w', encoding='utf-8', newline='') as f: + fields = ['name', 'age', 'job'] + writer = csv.DictWriter(f, fields, delimiter=';') + writer.writeheader() + for dikt in list_of_dicts: + writer.writerow(dikt) + if __name__ == "__main__": main() diff --git a/some.csv b/some.csv new file mode 100644 index 0000000..3e42da7 --- /dev/null +++ b/some.csv @@ -0,0 +1,5 @@ +name;age;job +Маша;25;Scientist +Вася;8;Programmer +Дуся;18;Small boss +Эдуард;48;Big boss From 85ece161a9dbc60a51f03223f2e1869d0d27a08c Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Wed, 15 Sep 2021 15:46:05 +0300 Subject: [PATCH 5/9] corrected the comments --- .gitignore | 3 +++ 2_files.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index af6d502..7a4e34a 100644 --- a/.gitignore +++ b/.gitignore @@ -121,3 +121,6 @@ dmypy.json # Pyre type checker .pyre/ +referat.txt +referat2.txt +some.csv \ No newline at end of file diff --git a/2_files.py b/2_files.py index 36eb883..e1627f1 100644 --- a/2_files.py +++ b/2_files.py @@ -19,7 +19,7 @@ def main(): """ with open(r'referat.txt', encoding='utf-8') as f: content = f.read() - string_len = (len(content)) + string_len = len(content) words_count = len((content.split())) sign_replace = content.replace('.', '!') From 60e952b902d5aadf4a19fc9aec4b976c9de476eb Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Wed, 15 Sep 2021 16:09:05 +0300 Subject: [PATCH 6/9] corrected the comments --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7a4e34a..80f5178 100644 --- a/.gitignore +++ b/.gitignore @@ -123,4 +123,6 @@ dmypy.json .pyre/ referat.txt referat2.txt -some.csv \ No newline at end of file +some.csv +# idea +.idea/ \ No newline at end of file From 09c8a94055cab1be864f1cfd7dd08e23c9f920a9 Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Wed, 15 Sep 2021 16:10:17 +0300 Subject: [PATCH 7/9] corrected the comments --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 80f5178..9d64d58 100644 --- a/.gitignore +++ b/.gitignore @@ -121,8 +121,6 @@ dmypy.json # Pyre type checker .pyre/ -referat.txt -referat2.txt -some.csv + # idea .idea/ \ No newline at end of file From f02129ed1ef72c28825444c64970eba503b237cc Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Wed, 15 Sep 2021 16:14:50 +0300 Subject: [PATCH 8/9] corrected the comments --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9d64d58..3e66444 100644 --- a/.gitignore +++ b/.gitignore @@ -123,4 +123,4 @@ dmypy.json .pyre/ # idea -.idea/ \ No newline at end of file +.idea \ No newline at end of file From 4151963e1f9ddb6d07033ded99ee7c8d4ee5d9b5 Mon Sep 17 00:00:00 2001 From: ktulhoo86 Date: Wed, 15 Sep 2021 16:24:02 +0300 Subject: [PATCH 9/9] corrected the comments --- .gitignore | 4 ++-- .idea/.gitignore | 3 --- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/learn-homework-2.iml | 14 -------------- .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 7 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/learn-homework-2.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 3e66444..ede9a9c 100644 --- a/.gitignore +++ b/.gitignore @@ -122,5 +122,5 @@ dmypy.json # Pyre type checker .pyre/ -# idea -.idea \ No newline at end of file +# IntellijIdea files +.idea/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/learn-homework-2.iml b/.idea/learn-homework-2.iml deleted file mode 100644 index 0a2ad20..0000000 --- a/.idea/learn-homework-2.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index d1e22ec..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 0225a5a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file