Here's a teaser for you, a Rotor class.
run code to test.
to use the rotor class from a function:
class Rotor: def __init__(self): self.iterno = 1 self.maxiter = 26 def __iter__(self): return self def next(self): try: if self.iterno > self.maxiter: raise StopIteration else: self.iterno += 1 return self.iterno - 1 except StopIteration: self.iterno = 2 return self.iterno - 1 class TestRotor: def __init__(self): self.rotor_1 = Rotor() def click(self, who): return who.next() def tryme(self): print(self.click(self.rotor_1)) for a_click in range(30): print(self.click(self.rotor_1)) if __name__ == '__main__': testit = TestRotor() testit.tryme()looking at the code in TestRotor,
self.rotor_1 = Rotor()creates a new rotor object,
x = self.rotor_1.next()will give you the next click. it resets to 1 after the 26th click
run code to test.
to use the rotor class from a function:
rotor1 = Rotor() for x in range(10): print(rotor1.next())