From be275fa1017d18a2d194e3a6022ea3079a3dea58 Mon Sep 17 00:00:00 2001 From: Neuf Date: Mon, 15 Sep 2025 01:57:35 +0500 Subject: [PATCH] =?UTF-8?q?3-=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Module16/03_running_nums/main.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Module16/03_running_nums/main.py b/Module16/03_running_nums/main.py index 9b7f69c..da5e83e 100644 --- a/Module16/03_running_nums/main.py +++ b/Module16/03_running_nums/main.py @@ -1 +1,32 @@ # TODO здесь писать код +def show_list(collection, secret): + if secret == 'first': + print('Изначальный список:', end=' ') + elif secret == 'after': + print('Сдвинутый список:', end=' ') + print('[', end='') + for i_collection in range(len(collection) - 1): + print(collection[i_collection], end=', ') + print(collection[len(collection) - 1], end=']') + print() + +def rebuild_list(collection, index): + new_collection = [] + step = len(collection) + while step > 0: + if len(collection) <= index or index < 0: + index %= len(collection) + # elif abs(step + index) == 0: + # index = 0 + # elif index < 0: + # index = abs(len(collection)- 1 - index) % len(collection) + new_collection.append(collection[index]) + index += 1 + step -= 1 + return new_collection + +list_for_view = [1, 2, 3, 4, 5] + +shift = int(input('Сдвиг: ')) +show_list(list_for_view, 'first') +show_list(rebuild_list(list_for_view, shift), 'after') \ No newline at end of file