Answer to Question #289757 in Python for pooja

Question #289757

jeff ordered several items from an online shop. After recieving the order he found that some were faulty. So he wants to seperatethe faulty items from the rest. You are given that prices of the item Jeff ordered, where a negative sign indicates a faulty item. Write a program to shift prices of all the faulty items to the left without changing the relatie order of the input.


SAMPLE INPUT 1:

11 -12 13 -14 15 16

SAMPLE OUTPUT 1:

-12 -14 11 13 15 16


SAMPLE INPUT 2:

21 11 -3 -2 9

SAMPLE OUTPUT 2:

-3 -2 21 11 9


1
Expert's answer
2022-01-22T16:36:43-0500
'''
    jeff ordered several items from an online shop.
    After recieving the order he found that some were faulty.
    So he wants to seperatethe faulty items from the rest.
    You are given that prices of the item Jeff ordered,
    where a negative sign indicates a faulty item.
    Write a program to shift prices of all the faulty
    items to the left without changing the relatie order of the input.
'''


Price = [11, -12, 13, -14, 15, 16]
print("Input: ",Price)


Output=[]
for r in range(0,len(Price)):
    if(Price[r]<0):
        Output.append(Price[r])
for r in range(0,len(Price)):
    if(Price[r]>=0):
        Output.append(Price[r])
        
print("output: ",Output)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS