19. Problem to remove negative elements from the list

We will take a user input as a list & iterate all the values one by one with the python loop to remove negative elements from it. Print only positive values with the help of the below-given steps.

Remove negative elements from list:

Steps to solve the program
  1. Take a list as input.
  2. Using for loop and if statement check whether an element from the given list is negative or positive.
  3. Print only positive elements.
				
					#Input list
list1 = [3,5,-8,0,-20,-55]

#Checking for positive values
for value in list1:
    if value >= 0:
        #Printing output
        print(value,end=" ")
				
			

Output :

				
					3 5 0
				
			

Related Articles

removing certain elements a list

List of elements divided by a number

Leave a Comment