3-задание выполнено

This commit is contained in:
Neuf
2025-09-15 01:57:35 +05:00
parent fc38f775b4
commit be275fa101

View File

@@ -1 +1,32 @@
# TODO здесь писать код # 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')