Answer to Question #265953 in Python for Jyo

Question #265953

Yup are given a space separated list of integers as input,write a program to replace all non positive numbers in a list with the last positive number encountered


1
Expert's answer
2021-11-15T00:22:58-0500
arr = [int(i) for i in input().split()]
c = -1
for i in range(len(arr)):
    if arr[i] >= 0:
        c = arr[i]
    if arr[i] < 0:
        if c >= 0:
            arr[i] = c




print(*arr)

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