Even Number Generator
Write a generator function even_numbers(limit) that yields every even number from 2 up to limit, then print all the values it produces.
What the problem means: instead of building a full list of even numbers up front, yield each one lazily — this is the core generator pattern from this topic.
Approach: use yield inside a loop from 2 to limit (inclusive), stepping by 2, then join the generated values into one comma-separated line.
Input: One line: limit, a whole number.
Output: One line: the even numbers from 2 up to limit, comma-and-space separated.
10
2, 4, 6, 8, 10
- 2 <= limit <= 1000
Hint 1
Loop i from 2 to limit (inclusive), stepping by 2, and yield i each time.
Hint 2
range(2, limit + 1, 2) already produces exactly the even numbers you need — loop over it and yield each value.
Hint 3
", ".join(...) turns the generated values into the required comma-separated line.
evennumbers(limit) loops from 2 to limit in steps of 2 (range(2, limit + 1, 2)), yielding each value instead of returning a list — the values are produced lazily, one at a time, exactly like the countupto example in the notes. ", ".join(str(x) for x in evennumbers(limit)) then consumes the generator to build the final line.