Python Practice › Loop Programs › Program 65

Odd numbers 1-10 into a list

EasyLoop Programs · 65 of 90

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

Advertisement
Output
[1, 3, 5, 7, 9]

Approach

  1. Append each odd number.

Solution

Python
odds = []for n in range(1, 11):    if n % 2 == 1:        odds.append(n)print(odds)
Output
[1, 3, 5, 7, 9]

Learn the concept

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

More loop programs

← All 90 Loop Programs

Leave a Comment