class LookAndSay: def find_sequence(self, target): current = '1' for i in range(0, target): next = self.look_and_say(current) current = next return current def look_and_say(self, input): result ='' prev = None count = 0 for i in input: if prev == None: prev = i count = 1 elif prev != i: result += ("{}{}".format(count, prev)) prev = i count = 1 else: count += 1 if prev != None: result += ("{}{}".format(count, prev)) return result l = LookAndSay() input = 4 print("input = {} output = {}".format(input, l.find_sequence(input))) input = 5 print("input = {} output = {}".format(input, l.find_sequence(input)))