Answer to Question #266472 in Python for sai krishna

Question #266472

in the example there are 6 numbers 1,-2,3,-4,-5,6

the negative numbers in the given list are -2,-4 and -5 where the -2 is replaced with corresponding last positive number encountered which is 1.similarly -4 and -5 are replaced with 3

so the output should be 1 1 3 3 3 6

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
2021-11-16T23:55:07-0500
l = list(map(int, input().split()))


for i in range(len(l)):
    if l[i] < 0:
        l[i] = l[i-1]


print(*l)

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