-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNLTKSlotMachine.py
77 lines (72 loc) · 2.59 KB
/
NLTKSlotMachine.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
import itertools
from msvcrt import getch
from nltk.corpus import words
import random
class LetterToWordSlotMachine(object):
def letterCollector(self):
cases = ["A", "E", "I", "O", "U"]
active = bool
while active:
char1 = input("Enter a Vowel")
if char1.upper() in cases:
break
else:
print("Try Again, Enter A, E, I, O, or U")
while active:
char2 = input("Enter a Vowel or Consonant")
if char2.isdigit():
print("Error, please enter a letter")
else:
break
while active:
char3 = input("Enter another Vowel or Consonant")
if char3.isdigit():
print("Error, please enter a letter")
else:
break
letters = [char1.lower(), char2.lower(), char3.lower()]
return letters
def valid_words_generator(self):
validPermutations = []
checking = bool
while checking:
letters = LetterToWordSlotMachine().letterCollector()
permutations = [''.join(i) for i in itertools.product(letters, repeat = 3)]
for each in permutations:
if each in words.words():
validPermutations.append(each)
if not validPermutations:
print("No words could be generated, please enter new letters")
else:
break
print(', '.join(validPermutations))
return letters, validPermutations
def slot_machine(self, letters, wordlist):
pullLever = bool
while pullLever:
a = random.choice(letters)
b = random.choice(letters)
c = random.choice(letters)
result = a.upper()+b+c
print(result)
if result.lower() in wordlist:
print("Success")
print("Try Again?\nPress Space to Pull the Lever\nPress Any Other Key to Quit")
keypress = ord(getch())
if keypress == 32:
pass
else:
break
else:
print("Fail")
print("Try Again?\nPress Space to Pull the Lever\nPress Any Other Key to Quit")
keypress = ord(getch())
if keypress == 32:
pass
else:
break
return None
if __name__ == "__main__":
run = LetterToWordSlotMachine()
userLetters, userWords = run.valid_words_generator()
run.slot_machine(userLetters, userWords)