passwords = [ 'about', 'after', 'again', 'below', 'could', 'every', 'first', 'found', 'great', 'house', 'large', 'learn', 'never', 'other', 'place', 'plant', 'point', 'right', 'small', 'sound', 'spell', 'still', 'study', 'their', 'there', 'these', 'thing', 'think', 'three', 'water', 'where', 'which', 'world', 'would', 'write' ] final = passwords class FoundCondition(Exception): pass responses = [] for i in range(5): response = [*input("{}th letters: ".format(str(i)))] responses.append(response) def check(index, word, responses): if index == 5: raise FoundCondition(word) for a in responses[index]: if a == word[index]: check(index + 1, word, responses) for word in passwords: try: check(0, word, responses) except FoundCondition as e: print(str(e))