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