-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview.py
42 lines (37 loc) · 1.01 KB
/
review.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
import json, random
with open('words_only.json') as f:
cards = json.load(f)
def correct():
while True:
ui = input()
if ui == "yes":
return True
if ui == "no":
return False
t = input("practice (r)eading or (w)riting? ")
try:
while True:
card = random.choice(cards)
if t == "r":
print(card["character"])
input()
print(card["pinyin"])
print(card["definition"])
if correct():
card["read_correct"] += 1
print()
card["read_attempts"] += 1
elif t == "w":
print(card["pinyin"])
print(card["definition"])
input()
print(card["character"])
if correct():
card["write_correct"] += 1
print()
card["write_attempts"] += 1
else:
break
except KeyboardInterrupt:
with open('words_only.json', 'w') as f:
json.dump(cards, f, indent=2)