Python Practice › Loop Programs › Program 64

Even numbers 1-10 into a list

EasyLoop Programs · 64 of 90

Write a Python program that adds the even numbers from 1 to 10 into an empty list.

Advertisement
Output
[2, 4, 6, 8, 10]

Approach

  1. Append each even number.

Solution

Python
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.

More loop programs

← All 90 Loop Programs

Leave a Comment