From 9fe297681d854466e0d2b2ca2dcc650b1afb4938 Mon Sep 17 00:00:00 2001 From: dimaMUshalapugin Date: Sat, 20 May 2023 15:59:01 +0300 Subject: [PATCH 1/5] For code review --- 1_date_and_time.py | 18 +++++++++++++++--- 2_files.py | 13 ++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/1_date_and_time.py b/1_date_and_time.py index e72d76a..00fa774 100644 --- a/1_date_and_time.py +++ b/1_date_and_time.py @@ -7,13 +7,22 @@ 2. Превратите строку "01/01/20 12:10:03.234567" в объект datetime """ - +from datetime import datetime, timedelta, date def print_days(): """ Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + dt_now = datetime.now() + print(f"Сегодня: {dt_now.strftime('%d.%m.%Y')}") + + delta_yesterday = timedelta(days=1) + dt_yesterday = (dt_now - delta_yesterday).strftime('%d.%m.%Y') + print(f"Вчера было: {dt_yesterday}") + + delta_30_days_age = timedelta(days=30) + dl_30_days_ago = (dt_now-delta_30_days_age).strftime('%d.%m.%Y') + print(f'30 дней назад дата была: {dl_30_days_ago}') def str_2_datetime(date_string): @@ -21,7 +30,10 @@ def str_2_datetime(date_string): Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + incorrect_format = '01/01/20 12:10:03.234567' + date_time_obj = datetime.strptime(incorrect_format, '%d/%m/%y %H:%M:%S.%f') + print(type(date_time_obj)) + print(date_time_obj) if __name__ == "__main__": print_days() diff --git a/2_files.py b/2_files.py index 5072b13..58ddf1c 100644 --- a/2_files.py +++ b/2_files.py @@ -16,7 +16,18 @@ def main(): Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + with open('referat.txt', 'r', encoding='utf-8') as f: + context = f.read() + read_file = context + number_of_words = len(read_file.split()) + print(f'Количество слов составляет - {number_of_words}') + + replace_example = read_file.replace('.', '!') + print(replace_example) + with open('referat.txt', 'w', encoding='utf-8') as new_f: + new_f.write(replace_example) + new_f.close() + if __name__ == "__main__": main() From 5c28c5b01dae6757635842de2023ba0e74d360fc Mon Sep 17 00:00:00 2001 From: dimaMUshalapugin Date: Sat, 20 May 2023 19:43:18 +0300 Subject: [PATCH 2/5] For code review --- 3_dict_to_csv.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/3_dict_to_csv.py b/3_dict_to_csv.py index 44d6efb..286f3d0 100644 --- a/3_dict_to_csv.py +++ b/3_dict_to_csv.py @@ -9,13 +9,26 @@ 2. Запишите содержимое списка словарей в файл в формате csv """ - +import csv def main(): """ Эта функция вызывается автоматически при запуске скрипта в консоли В ней надо заменить pass на ваш код """ - pass + + dict = [ + {'name': 'Маша', 'age': 25, 'job': 'Scientist', 'status': 'married'}, + {'name': 'Вася', 'age': 8, 'job': 'Programmer', 'status': 'unmarried'}, + {'name': 'Эдуард', 'age': 48, 'job': 'Big boss', 'status': 'married'}, + ] + + print(dict[0]) + with open('export.csv', 'w', encoding='utf-8', newline='') as f: + fields = ['name', 'age', 'job', 'status'] + writer = csv.DictWriter(f, fields, delimiter=';') + writer.writeheader() + for element in dict: + writer.writerow(element) if __name__ == "__main__": main() From 1925a715ade94af30db1d92ce8a8ea1ca87d0c00 Mon Sep 17 00:00:00 2001 From: dimaMUshalapugin <111433557+dimaMUshalapugin@users.noreply.github.com> Date: Tue, 23 May 2023 16:33:33 +0300 Subject: [PATCH 3/5] Update 2_files.py --- 2_files.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/2_files.py b/2_files.py index 58ddf1c..627d509 100644 --- a/2_files.py +++ b/2_files.py @@ -18,15 +18,13 @@ def main(): """ with open('referat.txt', 'r', encoding='utf-8') as f: context = f.read() - read_file = context - number_of_words = len(read_file.split()) + number_of_words = len(context.split()) print(f'Количество слов составляет - {number_of_words}') - replace_example = read_file.replace('.', '!') + replace_example = context.replace('.', '!') print(replace_example) with open('referat.txt', 'w', encoding='utf-8') as new_f: new_f.write(replace_example) - new_f.close() if __name__ == "__main__": From 068a28798d8a23127af002e78108b7221895efcd Mon Sep 17 00:00:00 2001 From: dimaMUshalapugin <111433557+dimaMUshalapugin@users.noreply.github.com> Date: Tue, 23 May 2023 16:35:21 +0300 Subject: [PATCH 4/5] Update 2_files.py --- 2_files.py | 1 + 1 file changed, 1 insertion(+) diff --git a/2_files.py b/2_files.py index 627d509..5fbb4da 100644 --- a/2_files.py +++ b/2_files.py @@ -18,6 +18,7 @@ def main(): """ with open('referat.txt', 'r', encoding='utf-8') as f: context = f.read() + print(len(context)) number_of_words = len(context.split()) print(f'Количество слов составляет - {number_of_words}') From 8b1b180b9d0dc767fc9bcf660d24afbfc86d80de Mon Sep 17 00:00:00 2001 From: dimaMUshalapugin <111433557+dimaMUshalapugin@users.noreply.github.com> Date: Tue, 23 May 2023 16:44:56 +0300 Subject: [PATCH 5/5] Update 2_files.py --- 2_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2_files.py b/2_files.py index 5fbb4da..1f0dffc 100644 --- a/2_files.py +++ b/2_files.py @@ -24,7 +24,7 @@ def main(): replace_example = context.replace('.', '!') print(replace_example) - with open('referat.txt', 'w', encoding='utf-8') as new_f: + with open('referat1.txt', 'w', encoding='utf-8') as new_f: new_f.write(replace_example)