Python Practice › Function Programs › Program 27
Odd numbers from 1 to 100
Write a Python function that returns the odd numbers from 1 to 100.
Output
50 [1, 3, 5, 7, 9] ... [95, 97, 99]
Approach
list(range(1, 101, 2)).
Solution
def odds(limit=100): return list(range(1, limit + 1, 2)) result = odds()print(len(result), result[:5], "...", result[-3:])Output
50 [1, 3, 5, 7, 9] ... [95, 97, 99]
Learn the concept
New to this topic? Read the lesson, then come back.