Objective
Create a Python program with an iterator class: an object that can be looped over with for because it implements __iter__ and __next__.
Instructions
- Define the class
MyRangewith__init__(self, start, end, step), which stores the three values and an attributecurrent = start. __iter__returnsself.__next__raisesStopIterationifcurrent >= end; otherwise, it stores the current value, addssteptocurrentand returns the stored value.- Read a line with three integers:
start end step(with a positive step and at least one value in the range). Store the values withlist(MyRange(start, end, step)). - Show the values on one line and, on the next one,
Count: K.
0 10 2
0 2 4 6 8
Count: 5
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise