-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.py
81 lines (69 loc) · 1.92 KB
/
password.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# /usr/local/bin/Python3
from wordhoard import Synonyms
import time
import random
import sys
wins = attempts = 0
SYN_LOOKUP = Synonyms
WORD_FILE_LOC = "password/wordlist.txt"
NUM_CLUES = 3
def create_word_list():
wordlist = open(WORD_FILE_LOC).read().splitlines()
words = []
for word in wordlist:
if len(word) > 3:
words.append(word)
random.shuffle(words)
return words
def restart():
choice = input("Play again: Y or N? ").strip().lower()
if choice == "y":
game()
elif choice == "n":
sys.exit()
else:
print("I don't know what that means.")
restart()
def get_clues(password):
syn = SYN_LOOKUP(search_string=password)
return syn.find_synonyms()
def game():
global attempts, wins
idx = 0
password = None
clues = None
while clues is None:
password = words.pop()
clues = get_clues(password)
while idx < NUM_CLUES:
clue = clues[idx]
now = time.time()
future = now + 10
print("\nClue: " + clue)
guess = input("Guess: ").lower()
if guess == password or guess + "s" == password or guess == password[:-3]:
print("\nCorrect!")
wins += 1
break
elif now > future:
print(f"You ran out of time! The password was {password}.")
break
else:
print("\nIncorrect")
idx += 1
if idx == NUM_CLUES:
print(f"\nThe password was {password}.")
attempts += 1
print("Game over. Your score was %d / %d." % (wins, attempts))
print("-" * 10)
restart()
def start():
print(
"\nWelcome to Password. Given 3 clues, try to guess",
"the word. You have 10 seconds to respond to each clue. Good luck!\n",
)
delay = input("Press Return or Enter to continue...")
game()
if __name__ == "__main__":
words = create_word_list()
start()