Intermediate
A lazy range() generator
Write a generator function range(start, end, step = 1) that yields start, start + step, ... up to but not including end. Assume step is positive.
It must be lazy: range(0, Infinity) must work and hand out numbers one at a time.
Use it to fill #evens with the even numbers from 0 up to (not including) 20, written as 0, 2, 4, ..., 18.
What Check tests
range(1, 5)gives 1, 2, 3, 4range(0, 10, 3)gives 0, 3, 6, 9range(5, 5)gives nothing- It's lazy:
range(0, Infinity)hands out 0, then 1 - It's written as a generator (
function*) - The page shows
0, 2, 4, 6, 8, 10, 12, 14, 16, 18
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.