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
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)
Comments
Leave a comment