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
|
final = passwords
|
||||||
|
|
||||||
|
class FoundCondition(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
responses = []
|
responses = []
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
response = [*input("{}th letters: ".format(str(i)))]
|
response = [*input("{}th letters: ".format(str(i)))]
|
||||||
responses.append(response)
|
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:
|
for word in passwords:
|
||||||
foundword = None
|
try:
|
||||||
for a in responses[0]:
|
check(0, word, responses)
|
||||||
if a == word[0]:
|
except FoundCondition as e:
|
||||||
for b in responses[1]:
|
print(str(e))
|
||||||
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)
|
|
||||||
|
|
Loading…
Reference in New Issue