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
lst_of_int = [int(i) for i in input().split()]
curr = -1
for i in range(len(lst_of_int)):
if lst_of_int[i] >= 0:
curr = lst_of_int[i]
if lst_of_int[i] < 0:
if curr >= 0:
lst_of_int[i] = curr
print(*lst_of_int)
Comments
Leave a comment