From ea7c6b40622f96a52a9acc9892263657d58df700 Mon Sep 17 00:00:00 2001 From: Kateryna Tymchenko Date: Fri, 22 Oct 2021 18:47:21 +0300 Subject: [PATCH 1/7] Add new file to dk91_ktymchenko directory --- dk91_ktymchenko/README.rst | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 dk91_ktymchenko/README.rst diff --git a/dk91_ktymchenko/README.rst b/dk91_ktymchenko/README.rst new file mode 100644 index 0000000..adbbc64 --- /dev/null +++ b/dk91_ktymchenko/README.rst @@ -0,0 +1,9 @@ +Student: Kateryna Tymchenko + +Group: DK-91 + +# Contacts + +Telegram: @t_r_i_n_a +Ph.number: +380990919391 +Email: kate.timchenko.2001@gmail.com \ No newline at end of file From b44145a458dbb635f32442b9c4578b933622187b Mon Sep 17 00:00:00 2001 From: Kateryna Tymchenko Date: Fri, 22 Oct 2021 22:46:24 +0300 Subject: [PATCH 2/7] Changes were added to dk91_ktymchenko directory --- dk91_ktymchenko/README.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/dk91_ktymchenko/README.rst b/dk91_ktymchenko/README.rst index adbbc64..044f3b1 100644 --- a/dk91_ktymchenko/README.rst +++ b/dk91_ktymchenko/README.rst @@ -1,5 +1,4 @@ Student: Kateryna Tymchenko - Group: DK-91 # Contacts From 26fcf5d974fcf4a80229ad0f1f3a9a5a502866b8 Mon Sep 17 00:00:00 2001 From: Kateryna Tymchenko Date: Fri, 22 Oct 2021 22:48:21 +0300 Subject: [PATCH 3/7] Some changes were added to dk91_ktymchenko directory --- dk91_ktymchenko/README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/dk91_ktymchenko/README.rst b/dk91_ktymchenko/README.rst index 044f3b1..adbbc64 100644 --- a/dk91_ktymchenko/README.rst +++ b/dk91_ktymchenko/README.rst @@ -1,4 +1,5 @@ Student: Kateryna Tymchenko + Group: DK-91 # Contacts From 27e5bf39d2b29880f29f2ec1fe5594ffbaac94b9 Mon Sep 17 00:00:00 2001 From: Kateryna Tymchenko Date: Sun, 24 Oct 2021 16:25:42 +0300 Subject: [PATCH 4/7] A program for counting the number of words in a text document was added to dk91_ktymchenko directory --- dk91_ktymchenko/word_counter.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 dk91_ktymchenko/word_counter.py diff --git a/dk91_ktymchenko/word_counter.py b/dk91_ktymchenko/word_counter.py new file mode 100644 index 0000000..9ad88ad --- /dev/null +++ b/dk91_ktymchenko/word_counter.py @@ -0,0 +1,7 @@ +openFile = open("file.txt") +readFile = openFile.read() +text = readFile.lower() +unique = set(text.split()) + +for word in unique: + print(f'{word}: {text.count(word)}') \ No newline at end of file From adf9ac4773dc1eef204b7f8155146bdd23f7697c Mon Sep 17 00:00:00 2001 From: Kateryna Tymchenko Date: Sun, 24 Oct 2021 16:28:56 +0300 Subject: [PATCH 5/7] New text file was added to dk91_ktymchenko directory --- dk91_ktymchenko/text.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 dk91_ktymchenko/text.txt diff --git a/dk91_ktymchenko/text.txt b/dk91_ktymchenko/text.txt new file mode 100644 index 0000000..1b98c0a --- /dev/null +++ b/dk91_ktymchenko/text.txt @@ -0,0 +1,5 @@ +The ancient Greeks first had the idea of getting men together every four years to hold and witness sporting events (in those days women did not participate, though they had their own, independent, events). The idea was to have the best athletes from all over Greece gather in one field and compete every four years. All wars and fighting had to stop while the athletes and their supporters came together in the town of Olympia for a few days to compete in a few events, mostly related to warfare (throwing the javelin, running, wrestling, boxing and chariot racing). +The first written reference to the Games is 776 BC. They lasted until 389 AD. The idea of having the modern Games was suggested in the mid 19th century but they weren't a world event until 1896. Besides being postponed because of wars, they have been held since then every four years in different cities around the world. +The Olympic Games have many important symbols that most people recognize. The five rings that appear on the Olympic flag (coloured yellow, green, blue, black and red) were introduced in 1914. They represent the five continents of Africa, the Americas, Australia, Asia and Europe. The flag is raised in the host city and then flown to the next one where it is kept until the next Games. The Olympic torch, a major part of the ancient Games, was brought back in 1928 and is carried with great fanfare and publicity to the host city where it lights the burning flame of the Games. It is kept burning until the close of the Games. The torch symbolizes purity, the drive for perfection and the struggle for victory. +The rousing Olympic anthem is the simply named "Olympic Music" by John Williams, who wrote it for the 1984 Olympics, held in Los Angeles. What you hear first are the forty or so notes played on horns which form the "Bugler's Dream" (also called "Olympic Fanfare") by Leo Arnaud, first played in the 1968 Games. +The torch, fanfare and flag are clearly evident in the Opening Ceremony, when everyone formally welcomes the participants and the Games can begin. Here we find the dramatic and colourful March of Nations, in which all the athletes from each country go into the venue to the sound of their country's anthem and march behind their flags, thus becoming representatives of their countries. \ No newline at end of file From b3da41448a4e25db35bbc0feff478d0d8f5be2e0 Mon Sep 17 00:00:00 2001 From: Kateryna Tymchenko Date: Sun, 24 Oct 2021 16:39:46 +0300 Subject: [PATCH 6/7] New text file was added to dk91_ktymchenko directory --- dk91_ktymchenko/text.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dk91_ktymchenko/text.txt b/dk91_ktymchenko/text.txt index 1b98c0a..9b6afb3 100644 --- a/dk91_ktymchenko/text.txt +++ b/dk91_ktymchenko/text.txt @@ -1,5 +1,5 @@ The ancient Greeks first had the idea of getting men together every four years to hold and witness sporting events (in those days women did not participate, though they had their own, independent, events). The idea was to have the best athletes from all over Greece gather in one field and compete every four years. All wars and fighting had to stop while the athletes and their supporters came together in the town of Olympia for a few days to compete in a few events, mostly related to warfare (throwing the javelin, running, wrestling, boxing and chariot racing). The first written reference to the Games is 776 BC. They lasted until 389 AD. The idea of having the modern Games was suggested in the mid 19th century but they weren't a world event until 1896. Besides being postponed because of wars, they have been held since then every four years in different cities around the world. -The Olympic Games have many important symbols that most people recognize. The five rings that appear on the Olympic flag (coloured yellow, green, blue, black and red) were introduced in 1914. They represent the five continents of Africa, the Americas, Australia, Asia and Europe. The flag is raised in the host city and then flown to the next one where it is kept until the next Games. The Olympic torch, a major part of the ancient Games, was brought back in 1928 and is carried with great fanfare and publicity to the host city where it lights the burning flame of the Games. It is kept burning until the close of the Games. The torch symbolizes purity, the drive for perfection and the struggle for victory. +The Olympic Games have many important symbols that most people recognize. The five rings that appear on the Olympic flag (coloured yellow, green, blue, black and red) represent the five continents of Africa, the Americas, Australia, Asia and Europe. The flag is raised in the host city and then flown to the next one where it is kept until the next Games. The Olympic torch, a major part of the ancient Games, was brought back in 1928 and is carried with great fanfare and publicity to the host city where it lights the burning flame of the Games. It is kept burning until the close of the Games. The torch symbolizes purity, the drive for perfection and the struggle for victory. The rousing Olympic anthem is the simply named "Olympic Music" by John Williams, who wrote it for the 1984 Olympics, held in Los Angeles. What you hear first are the forty or so notes played on horns which form the "Bugler's Dream" (also called "Olympic Fanfare") by Leo Arnaud, first played in the 1968 Games. The torch, fanfare and flag are clearly evident in the Opening Ceremony, when everyone formally welcomes the participants and the Games can begin. Here we find the dramatic and colourful March of Nations, in which all the athletes from each country go into the venue to the sound of their country's anthem and march behind their flags, thus becoming representatives of their countries. \ No newline at end of file From 9a54b94733ad56370e67e75897d9f10e66b1294e Mon Sep 17 00:00:00 2001 From: Kateryna Tymchenko Date: Thu, 11 Nov 2021 16:10:10 +0200 Subject: [PATCH 7/7] DK-91_Tymchenko_Kateryna. mkr1: answers --- mkr1/DK-91_Tymchenko_Kateryna_Olehivna.rst | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/mkr1/DK-91_Tymchenko_Kateryna_Olehivna.rst b/mkr1/DK-91_Tymchenko_Kateryna_Olehivna.rst index 29304d0..178b64f 100644 --- a/mkr1/DK-91_Tymchenko_Kateryna_Olehivna.rst +++ b/mkr1/DK-91_Tymchenko_Kateryna_Olehivna.rst @@ -4,21 +4,66 @@ #. Що таке Git та для чого використовується? Як створити новий локальний репозиторій Git? Наведіть команди. + +– Git – система управління версіями з розподіленою архітектурою. У Git кожна робоча копія коду сама собою є репозиторієм. +Команда git init створює у вказаному каталозі підкаталог .git, що містить всі необхідні файли репозиторію - структуру Git репозиторію. #. Яким чином можна додати зміни до вже створеного (останнього) коміту? Наведіть приклад. Чи варто так робити в основних публічних гілках віддаленого репозиторію? Якщо так, коли? Якщо ні, чому? +- Команда git commit --amend дає змогу об'єднати проіндексовані зміни з попереднім коммітом без створення нового комміту. Її можна використовувати для редагування коментаря до попереднього коміту без зміни стану коду в ньому. Але така зміна не лише редагує останній коміт, а й повністю його замінює. Тобто змінений коміт стане новою сутністю з окремим посиланням. +Змінювати коміт має сенс тоді, коли він твій і не впливає на інших користувачів. Змінювати чужий коміт у публічному репозиторії погано. + #. Множина (set). Для чого слугує? Чим відрізняється від списку (list) та кортежа (tuple)? Наведіть приклади використання. + +- List – впорядкована послідовність елементів, Set – окремий список елементів, який не є впорядкованим. Тобто, перша різниця полягає у тому, що list и tuple — це завжди упорядковані послідовності об'єктів, на відміну від Set. +На відміну від списків чи кортежів, множина не містить дублікатів. Іншими словами, елементи множини завжди унікальні. +Тож, множина зручно видаляє дублікати: +set_example = {1, 1, 2, 3, 3, 3} +# {1, 2, 3} +Тож, список підходить, якщо послідовність планується змінювати, або +планується поступово додавати нові елементи до послідовності або видаляти старі. Кортеж підходить, якщо послідовність не планується змінювати, бо все, що потрібно від послідовності, це можливість по черзі перебирати постійний набір елементів. Через відсутність можливості зміни, кортежі працюють набагато швидше за списки. #. Яким чином можна виконати замір швидкості виконання блоку коду Python? Що є швидшим для розрахунку квадратного кореня: оператор піднесення до степеню, функція піднесення для степеню з бібліотеки ``math`` чи спеціалізована функція взяття квадратного кореню з ``math``? Наведіть приклад коду, що визначає швидкість виконання для кожного з випадків. +- Замір швидкості можна віконати за допомогою timeit.default_timer() - він вибере функцію синхронізації, яка має вищу роздільну здатність для будь-якої платформи. + #. Що таке she-bang та для чого використовується? Який she-bang буде максимально коректним для Python 3? Чи використовується she-bang в скриптах? Якщо так, чому? Якщо ні, коли? + +- Рядок shebang у будь-якому скрипті визначає здатність скрипта виконуватися як автономний виконуваний файл без попереднього введення python у terminal або при подвійному клацанні по ньому у файловому менеджері (при правильному налаштуванні). Це не обов'язково, але зазвичай поміщається туди, тому коли хтось бачить файл, відкритий в редакторі, він відразу розуміє, на що дивиться. +#!/usr/bin/env python3 - she-bang для Python 3 #. Лямбда-функції. Де використовуються? Які переваги та недоліки мають? Наведіть приклад лямбда-функції та її використання, а також аналог з використанням звичайної (не лямбда-) функції. +- Python-лямбди - це маленькі анонімні функції, що підкоряються більш строгому, але лаконічнішому синтаксису, ніж звичайні функції Python. Вони корисні лише тому випадку, коли потрібна одноразова функція. Складається завжди з одного рядка. +Приклад простої функції, яка повертає "True" для парних чисел та "False" — для непарних: +def even_fn(x): + if x % 2 == 0: + return True + return False +print(list(filter(even_fn, [1, 3, 2, 5, 20, 21]))) +#результат: [2, 20] + +Той же самий код з використанням лямбда-функії: +print(list(filter(lambda x: x % 2 == 0, [1, 3, 2, 5, 20, 21]))) + #. Тернарний оператор Python. Навести код, що **за допомогою тернарного оператора** присвоїть змінній ``var`` значення ``69`` якщо змінна ``arg`` задана в ``None``, в іншому випадку – присвоїть значення ``arg``. Як зробити це без тернарного оператора? Наведіть приклад коду. + +- Тернарний оператор - це конструкція, яка за своєю дією аналогічна конструкції if-else, але є виразом. Тернарний оператор - єдиний у своєму роді оператор, що вимагає три операнди +def test(var): + arg = None + if arg == None: + return 69 + return arg + +або +arg = None +var = 69 if arg == 'None' else arg #. Які цикли Python вам відомі? Яким чином можна примусово вийти з циклу? + +- Існує 2 цикли: for і while. Оператор break достроково перериває цикл. +While - один із найбільш універсальних циклів у Python, але досить повільний. Виконує тіло циклу до того часу, поки умова циклу істинна. Цикл for трохи складніший, трохи менш універсальний, але виконується набагато швидше за цикл while. Цей цикл проходить по будь-якому об'єкту, що ітерується (наприклад рядку або списку), і під час кожного проходу виконує тіло циклу.