-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
49 lines (38 loc) · 1.2 KB
/
game.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
'''
spanish game
April Volzer amv87
Final project1
May 2019
'''
from random import randint
class Game:
def __init__(self):
self.dictionary = {}
f = open("words.txt", 'r')
lines = f.readlines()
f.close()
#english-spanish dictionary
for line in lines:
x = line.split(' ')
spanish = x[0]
english = x[1].rstrip()
self.dictionary[english] = spanish
self.english_list = list(self.dictionary.keys())
self.word_list = []
def get_term(self):
english = self.english_list[randint(0, len(self.english_list)-1)]
return self.dictionary[english]
def get_answer(self, term):
self.term = term
return self.dictionary.get(term)
def check_answer(self, answer):
if answer in self.dictionary:
spanish = self.dictionary[answer]
for word in self.word_list:
if word.get_word() == spanish:
self.word_list.remove(word)
return True
if __name__ == "__main__":
test = Game()
print(test.get_term())
print(test.get_answer("dinero"))