???????: 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).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

????????:
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).

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education