Prob2.py
mr-shrayan opened this issue · comments
Under "def next" why can't "MyGen.current_state_of_next += 1" be replaced with "num += 1". If replaced an infinite loop is created with an output 1.
If the "if" statement and the 'raise StopIteration' are commented then an infinite loop displaying whoe numbers starts.
First of all there is a logical error in this class definition. Current_state_of_next is declared as class variable but should be declared as instance variable. With such class declaration if you will create another gen2 = MyGen(1,10) it won't work. Second: if you write num += 1 in next then it will be created with each call and won't store value between the calls