20. Problem to get a list of elements divided by a number

In this program, we will take a user input as a list & iterate all the elements one by one with the python loop. Print the list of elements divided by a number with the help of the below-given steps.

Elements divided by number:

Steps to solve the program
  1. Take a list as input and create an empty list.
  2. Using for loop and if statement check whether an element from the given list is divisible by 3 or 7.
  3. Add only those elements to the empty list to get the list of elements divided by number.
  4. Print the list to see the output.
				
					#Input list
list1 = [3,7,0,2,6,14,88,21]

#Creating empty list
list2 = []

for value in list1:
#Checking whether the value is 
#divided by either 3 or 7
    if value%3 == 0 or value%7 == 0:
        list2.append(value)

#Printing output
print(value)
				
			

Output :

				
					[3, 7, 0, 6, 14, 21]
				
			

Related Articles

Remove negative elements from the list

Check whether the list is palindrome or not

Leave a Comment