|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
In this task, we develop a class with which elements of a list can be used as often as desired, in cycles. The class Ez (short for "perpetual cycle") should have the following methods:
A constructor to pass any iterable (that is, list, tuple, ...). The default value of this iteration should be None.
A method set_data, which is also passed an Iterable. After calling set_data, this iterable should be used, starting with its first element.
A method next that provides a reference to the next element of the data. If no further data are available, the first element should be started again. When set_data is called, next should always start over again.
First write the constructor and set_data. Consider which attributes an object of this class must remember.
Then write the method next. If the iteration of the Ez object does not contain any elements, or if there is no Iterable, the method should return None.
#这些代码不能更改,用于检验
e = Ez([1,2,3])
assert e.next() == 1
assert e.next() == 2
assert e.next() == 3
assert e.next() == 1
|
|