Answered You can hire a professional tutor to get the answer.
Python programming Q3. 40 points Problem Statement: Ask the user to enter a sequence of numbers. Let's call this sequence A.
Python programming
Q3. 40 points Problem Statement:
Ask the user to enter a sequence of numbers. Let's call this sequence A. Thereafter ask the user to enter a sequence of numbers B which indicates positions which are most important. We generate a sequence as follows:
The most important numbers specified by B must be at the beginning and in the opposite order of what they were in A.
The remaining number from A are to be sorted.
Sample Output 1:
Please enter A: 9 3 1 20 11 0
Please enter B: 3 6
The sequence you want is: 0 1 3 9 11 20
The numbers at positions 3 and 6, 1 and 0. They are at the beginning and in opposite order of what they appeared in list A. The other numbers are sorted.
Sample Output 2:
Please enter A: 9 3 1 20 11 0
Please enter B: 1 6
The sequence you want is: 0 9 1 3 11 20
The numbers at positions 1 and 6 are 9 and 0 respectively. They are at the beginning and in the opposite order of what they appeared in list A. The other numbers are sorted.
Sample Output 3:
Please enter A: 9 3 1 20 11 0
Please enter B: 1 4 6
The sequence you want is: 0 20 9 1 3 11
The numbers at positions 1, 4 and 6 are 9, 20 and 0 respectively. They are at the beginning and in opposite order of what they appeared in list A. The other numbers are sorted.
def insSort(L):
i = 1
while i < len(L):
j = i
while j > 0 and L[j-1] > L[j]:
temp = L[j-1]
L[j-1] = L[j]
L[j] = temp
j -= 1
i += 1
def main():
inp = input("Please enter A: ")
oglst = [int(x) for x in inp.split()]
inp2 = input("Please enter B: ")
pos = [(int(x)-1) for x in inp2.split()]
lst = []
new = []
for i in range(len(oglst)):
if i not in pos:
lst.append(oglst[i])
else:
new.append(oglst[i])
insSort(lst)
insSort(new)
new += lst;
print("The sequence you want is: ", end="")
for i in new:
print(i,end = " ")
main()
What should I change