## Problem 5: Remainder Generator Like functions, generators can also be higher-order. For this problem, we will be writing `remainders_generator`, which yields a series of generator objects. `remainders_generator` takes in an integer `m`, and yields `m
时间: 2024-01-27 21:03:57 浏览: 74
-1` generator objects. Each generator object should generate the remainders of consecutive integers modulo `m`. Here's an example:
```python
>>> gen = remainders_generator(3)
>>> next(gen[0])
0
>>> next(gen[0])
1
>>> next(gen[0])
2
>>> next(gen[0])
0
>>> next(gen[1])
0
>>> next(gen[1])
1
>>> next(gen[1])
2
>>> next(gen[1])
0
>>> next(gen[0])
1
```
In the example above, `remainders_generator(3)` yields 2 generator objects, which can be accessed using `gen[0]` and `gen[1]`. The first generator (`gen[0]`) produces the sequence `0, 1, 2, 0, 1, 2, 0, ...` and the second generator (`gen[1]`) produces the same sequence.
Note: Your implementation should not store any of the remainders in memory. Instead, it should generate them on the fly using the `yield` keyword.
阅读全文
相关推荐


















