Odd numbers from 1 to 100

EasyFunction Programs · 27 of 39

Write a Python function that returns the odd numbers from 1 to 100.

Advertisement
Output
50 [1, 3, 5, 7, 9] ... [95, 97, 99]

Approach

  1. list(range(1, 101, 2)).

Solution

Python
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]
Advertisement

Learn the concept

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

More function programs

← All 39 Function Programs