????????: Write a Python program that takes a list and a step size(integer number) as inputs from the user. Your program should swap elements from the front and back while maintaining the step size....


????????:
Write a Python program that takes a list and a step size(integer number) as

inputs from the user. Your program should swap elements from the front and

back while maintaining the step size.
[You are not allowed to use built-in replace() function]
================================
Sample Input 1:
A,B,C,D,E,F,G,H
2
Sample Output 1:
Before swap: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
After swap: ['H', 'B', 'F', 'D', 'E', 'C', 'G', 'A']
Explanation 01:
Here in the input, a list is given as input, and 2 is the step size.

‘A’(index0) swaps places with ‘H’(index -1). Then step size increments by

2. 0+2= 2. Swapping starts from index2. ‘C’(index2) swaps places with

‘F’(index -3).
================================
Sample Input 2:
A,B,C,D,E,F,G,H
5
Sample Output 2:
Step size is not suitable
Explanation 02:
Here in the input, a list is given as input, and 5 is the step size which

is greater than half of the list length. So swapping is not possible.
================================
Sample Input 3:
A,B,C,D,E,F,G,H,I,J,K
3
Sample Output3:
Before swap: ['A','B', 'C', 'D', 'E', 'F', 'G','H', 'I', 'J','K']
After swap: ['K', 'B', 'C', 'H', 'E', 'F', 'G', 'D', 'I', 'J', 'A']
Explanation 03:
Here in the input, a list is given as input, and 3 is the step size.

‘A’(index0) swaps places with ‘K’(index -1). Then step size increments by

3. 0+3= 3. Swapping starts from index3. ‘D’(index3) swaps places with

‘H’(index -4).



Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here