passwords v2, with recursion

This commit is contained in:
randomuser 2023-07-14 23:29:10 -05:00
parent dfdb52340a
commit f94a7aa9e2
1 changed files with 15 additions and 14 deletions

View File

@ -10,23 +10,24 @@ passwords = [
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:
foundword = None
for a in responses[0]:
if a == word[0]:
for b in responses[1]:
if b == word[1]:
for c in responses[2]:
if c == word[2]:
for d in responses[3]:
if d == word[3]:
for d in responses[4]:
if d == word[4]:
foundword = word
if foundword:
print(foundword)
try:
check(0, word, responses)
except FoundCondition as e:
print(str(e))