Answer to Question #292616 in Python for Dhanaraju

Question #292616

Separate Faulty Items


Jeff Ordered several items from an online shop.After receiving the order, he found that some were faulty.So, he wants to separate the faulty items from the rest.

You are given the prices of the items jeff ordered, where a negative sign indicates a faulty item.Write a program to shift the prices of all the faulty items to the left without changing the relative order of the input.


Input

The first line of input contains space separated integers.


sample input1

11 -12 13 -14 15 16

sample output1

-12 -14 11 13 15 16


sample input2

21 11 -3 -2 9

sample output2

-3 -2 21 11 9


1
Expert's answer
2022-01-31T16:17:56-0500
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