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
- Take a list as input and create an empty list.
- Using for loop and if statement check whether an element from the given list is divisible by 3 or 7.
- Add only those elements to the empty list to get the list of elements divided by number.
- 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
Python program to check whether the given list is palindrome or not.
Python Program to get a list of words which has vowels in the given string.
Python program to add 2 lists with extend method.
Python program to sort list data, with the sort and sorted method.
Python program to remove data from the list from a specific index using the pop method.
Python program to get the max, min, and sum of the list using in-built functions.