Python Practice › Loop Programs › Program 65
Odd numbers 1-10 into a list
Write a Python program that adds the odd numbers from 1 to 10 into an empty list.
Output
[1, 3, 5, 7, 9]
Approach
- Append each odd number.
Solution
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.