From a1f45ef1bfdc1b172f4366bd85e2e7e20b59e021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=9E=D0=BD?= =?UTF-8?q?=D1=8F=D0=BD=D0=BE=D0=B2?= Date: Tue, 14 Feb 2023 16:27:58 +0500 Subject: [PATCH] Did DZ5 - task 5.1[26], 5.2[28] --- .../inspectionProfiles/profiles_settings.xml | 6 -- .idea/misc.xml | 4 -- .idea/modules.xml | 8 --- .idea/python.iml | 8 --- .idea/vcs.xml | 6 -- .idea/workspace.xml | 60 ------------------- {.idea/DZ2 => DZ2}/.idea/.gitignore | 0 {.idea/DZ2 => DZ2}/.idea/DZ2.iml | 0 .../inspectionProfiles/profiles_settings.xml | 0 {.idea/DZ2 => DZ2}/.idea/misc.xml | 0 {.idea/DZ2 => DZ2}/.idea/modules.xml | 0 {.idea/DZ2 => DZ2}/task 2.1.py | 0 {.idea/DZ2 => DZ2}/task 2.2.py | 0 {.idea/DZ2 => DZ2}/task 2.3.py | 0 DZ4/task_4.1.py | 12 ++++ DZ4/task_4.2.py | 18 ++++++ DZ5/task_5.1.py | 16 +++++ DZ5/task_5.2.py | 13 ++++ 18 files changed, 59 insertions(+), 92 deletions(-) delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/python.iml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml rename {.idea/DZ2 => DZ2}/.idea/.gitignore (100%) rename {.idea/DZ2 => DZ2}/.idea/DZ2.iml (100%) rename {.idea/DZ2 => DZ2}/.idea/inspectionProfiles/profiles_settings.xml (100%) rename {.idea/DZ2 => DZ2}/.idea/misc.xml (100%) rename {.idea/DZ2 => DZ2}/.idea/modules.xml (100%) rename {.idea/DZ2 => DZ2}/task 2.1.py (100%) rename {.idea/DZ2 => DZ2}/task 2.2.py (100%) rename {.idea/DZ2 => DZ2}/task 2.3.py (100%) create mode 100644 DZ4/task_4.1.py create mode 100644 DZ4/task_4.2.py create mode 100644 DZ5/task_5.1.py create mode 100644 DZ5/task_5.2.py 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/misc.xml b/.idea/misc.xml deleted file mode 100644 index d56657a..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 614b3c1..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/python.iml b/.idea/python.iml deleted file mode 100644 index d0876a7..0000000 --- a/.idea/python.iml +++ /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 diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 004d2cb..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 1675756928340 - - - - - - - \ No newline at end of file diff --git a/.idea/DZ2/.idea/.gitignore b/DZ2/.idea/.gitignore similarity index 100% rename from .idea/DZ2/.idea/.gitignore rename to DZ2/.idea/.gitignore diff --git a/.idea/DZ2/.idea/DZ2.iml b/DZ2/.idea/DZ2.iml similarity index 100% rename from .idea/DZ2/.idea/DZ2.iml rename to DZ2/.idea/DZ2.iml diff --git a/.idea/DZ2/.idea/inspectionProfiles/profiles_settings.xml b/DZ2/.idea/inspectionProfiles/profiles_settings.xml similarity index 100% rename from .idea/DZ2/.idea/inspectionProfiles/profiles_settings.xml rename to DZ2/.idea/inspectionProfiles/profiles_settings.xml diff --git a/.idea/DZ2/.idea/misc.xml b/DZ2/.idea/misc.xml similarity index 100% rename from .idea/DZ2/.idea/misc.xml rename to DZ2/.idea/misc.xml diff --git a/.idea/DZ2/.idea/modules.xml b/DZ2/.idea/modules.xml similarity index 100% rename from .idea/DZ2/.idea/modules.xml rename to DZ2/.idea/modules.xml diff --git a/.idea/DZ2/task 2.1.py b/DZ2/task 2.1.py similarity index 100% rename from .idea/DZ2/task 2.1.py rename to DZ2/task 2.1.py diff --git a/.idea/DZ2/task 2.2.py b/DZ2/task 2.2.py similarity index 100% rename from .idea/DZ2/task 2.2.py rename to DZ2/task 2.2.py diff --git a/.idea/DZ2/task 2.3.py b/DZ2/task 2.3.py similarity index 100% rename from .idea/DZ2/task 2.3.py rename to DZ2/task 2.3.py diff --git a/DZ4/task_4.1.py b/DZ4/task_4.1.py new file mode 100644 index 0000000..13ab9eb --- /dev/null +++ b/DZ4/task_4.1.py @@ -0,0 +1,12 @@ +### 4.1[22]: Даны два неупорядоченных набора целых чисел (может быть, с повторениями). +# Выдать без повторений в порядке возрастания все те числа, которые встречаются в обоих наборах. +# Если таких чисел нет - выдать внятное диагностическое сообщение. +# Наборы (списки) чисел можно считать заданными и не вводить с клавиатуры + +arrA = [2, 4, 6, 8, 10, 12, 10, 8, 6, 4, 2] +arrB = [3, 6, 9, 12, 15, 18] +arrC = list(set(arrA) & set(arrB)) +if len(arrC)>0: + print(*sorted(arrC)) +else: + print('Повторяющихся чисел нет') \ No newline at end of file diff --git a/DZ4/task_4.2.py b/DZ4/task_4.2.py new file mode 100644 index 0000000..f74e26f --- /dev/null +++ b/DZ4/task_4.2.py @@ -0,0 +1,18 @@ +# В фермерском хозяйстве в Карелии выращивают чернику. Она растет на круглой грядке, причем кусты высажены только по окружности. +# Таким образом, у каждого куста есть ровно два соседних. Всего на грядке растет N кустов. +# Собирающий модуль за один заход, находясь непосредственно перед некоторым кустом, собирает ягоды с этого куста и с двух соседних с ним. +# Напишите программу для нахождения максимального числа ягод, которое может собрать за один заход собирающий модуль, находясь перед некоторым кустом. +# На входе задано количество ягод на каждом кусте. Не обязательно вводить их с клавиатуры, можно задать непосредственно в коде программы. + + +a = [1, 2, 3, 4, 5, 6, 7, 8] +b = list() +for i in range(len(a)): + if i == 0: + b.append(a[i]+a[i+1]+a[len(a)-1]) + elif (i>=1) and (i<(len(a)-1)): + b.append(a[i-1]+a[i]+a[i+1]) + else: + b.append(a[i-1]+a[i]+a[0]) + +print(f'Макс.кол-во ягод {max(b)}, собрано для куста {i}') diff --git a/DZ5/task_5.1.py b/DZ5/task_5.1.py new file mode 100644 index 0000000..a3e1bf3 --- /dev/null +++ b/DZ5/task_5.1.py @@ -0,0 +1,16 @@ +#### 5.1[26]: Напишите рекурсивную функцию для возведения числа a в степень b. Разрешается использовать только операцию умножения. Циклы использовать нельзя + +# Примеры/Тесты: +# (2,0) -> 1 +# (2,1) -> 2 +# (2,3) -> 8 +# (2,4) -> 16 + +def power(base, exp): + if (exp == 0): + return (1) + if (exp == 1): + return (base) + if (exp > 1): + return (base *power(base, exp-1)) +print("Результат возведения в степень равен:", power(2, 4)) \ No newline at end of file diff --git a/DZ5/task_5.2.py b/DZ5/task_5.2.py new file mode 100644 index 0000000..0899e9b --- /dev/null +++ b/DZ5/task_5.2.py @@ -0,0 +1,13 @@ +#### 5.2[28]: Напишите рекурсивную функцию sum(a, b), возвращающую сумму двух целых неотрицательных чисел. Из всех арифметических операций допускаются только +1 и -1. Циклы использовать нельзя + +# Примеры/Тесты: +# (0,0) -> 0 +# (0,2) -> 2 +# (3,0) -> 3 + +def summa(a, b): + if a == 0: + return b + else: + return summa(a-1, b+1) +print(summa(3, 0))