mass = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = len(mass) - 1
while i > 0:
mass[i], mass[i - 1] = mass[i - 1], mass[i]
i -= 1
print(*mass)
Объяснение:
другой код через for
for i in range(len(mass) - 1, 0, -1):
mass = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = len(mass) - 1
while i > 0:
mass[i], mass[i - 1] = mass[i - 1], mass[i]
i -= 1
print(*mass)
Объяснение:
другой код через for
mass = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(len(mass) - 1, 0, -1):
mass[i], mass[i - 1] = mass[i - 1], mass[i]
print(*mass)