Python Practice › Loop Programs › Program 64
Even numbers 1-10 into a list
Write a Python program that adds the even numbers from 1 to 10 into an empty list.
Output
[2, 4, 6, 8, 10]
Approach
- Append each even number.
Solution
evens = []for n in range(1, 11): if n % 2 == 0: evens.append(n)print(evens)Output
[2, 4, 6, 8, 10]
Learn the concept
New to this topic? Read the lesson, then come back.