passwords v2, with recursion
This commit is contained in:
parent
dfdb52340a
commit
f94a7aa9e2
29
passwords.py
29
passwords.py
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue