Answer to Question #285369 in Python for Ram

Question #285369

Numbers Replacement


Note: Start from the left end of the list.


sample input1

1 -2 3 -4 -5 6

sample output1

1 1 3 3 3 6


sample input2

1 11 -13 21 -19

sample output2

1 11 11 21 21


1
Expert's answer
2022-01-09T02:21:41-0500


Num = [1, -2, 3, -4, -5, 6]
#Num = [1, 11, -13, 21, -19]


print("Original Array: ",Num)        
for r in range(1,len(Num)):
    if(Num[r]<0):
        Num[r] = Num[r-1]
print("Modified Array: ",Num)

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