In this program, we will add even numbers to an empty list.
Steps to solve the program
- Take a list as input and create an empty list.
- Use for loop to iterate over each number of the input list.
- If the number is even then add it to the empty list.
- Print the output.
list1 = [2,3,5,76,9,0,16]
even = []
for val in list1:
if val%2 == 0:
even.append(val)
print("Even numbers: ",even)
Output :
Even numbers: [2, 76, 0, 16]