Python Practice › Loop Programs › Program 76

Copy even numbers to a new list

EasyLoop Programs · 76 of 90

Write a Python program to copy the even numbers from a list into an empty list.

Advertisement
Input
[2, 3, 5, 76, 9, 0, 16]
Output
[2, 76, 0, 16]

Approach

  1. Append numbers with remainder 0.

Solution

Python
a = [2, 3, 5, 76, 9, 0, 16]b = []for n in a:    if n % 2 == 0:        b.append(n)print(b)
Output
[2, 76, 0, 16]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More loop programs

← All 90 Loop Programs