/
games.py
94 lines (77 loc) · 1.99 KB
/
games.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
82
83
84
85
86
87
88
89
90
91
92
93
94
import helpers
import time
import random
import main
import operator
def def_first():
"""Game for matching word to definiton"""
content = helpers.init()
print('\nYou can exit at anytime by entering \'menu\'.\n')
random.shuffle(content)
count = len(content)
correct = 0
incorrect = 0
for word in content:
print('\n{}. {}'.format(operator.indexOf(content, word) + 1, word['definition']))
res = input('\nWhat word does this definition belong to?\n\t=>').lower()
if res == word['key'].lower():
count -= 1
correct += 1
if count > 0:
print('\nGood Job! next word!')
elif res == 'menu':
main.menu()
else:
incorrect += 1
count -= 1
if count > 1:
print('\nIncorrect. Next word.')
print('\nYou got {} correct and {} incorrect'.format(correct, incorrect))
helpers.callback(def_first)
def scrambled():
"""Unscramble the word"""
content = helpers.init()
print('\nYou can exit at anytime by entering \'menu\'.\n')
random.shuffle(content)
count = len(content)
correct = 0
incorrect = 0
i = 0
shuffled = []
for word in content:
scrmbld = helpers.scramble_string(word['key'])
shuffled.append(scrmbld)
for scr in shuffled:
res = input('\n{}. {}.\n\t=>'.format(i + 1, scr)).lower()
if res == content[i]['key'].lower():
count -= 1
correct += 1
if count > 0:
print('\nGood Job! next word!')
elif res == 'menu':
main.menu()
else:
incorrect += 1
count -= 1
if count > 1:
print('\nIncorrect. Next word.')
i += 1
print('\nYou got {} correct and {} incorrect'.format(correct, incorrect))
helpers.callback(scrambled)
def menu():
"""Menu Function"""
def run(func):
"""Calls functions"""
func()
menu()
print('\n\t\tVocab Arcade!')
choice = input("\nDo you want to play Guess the term (enter 'gtt') or Word Jumble (enter 'unscramble')? Enter 'x' to exit.\n\t=>").lower()
if choice == 'gtt':
run(def_first)
elif choice == 'unscramble':
run(scrambled)
elif choice == 'x':
return
else:
print('\n\tInvalid input.')
menu()