-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary(ver_2).py
72 lines (65 loc) · 2.25 KB
/
dictionary(ver_2).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
import random
import os
here = os.path.dirname(os.path.abspath(__file__))
select =''
while select != 'Q':
hist = []
li = ''
with open(os.path.join(here, '漢字と意味.txt'), encoding='utf8') as fp:
for i, l in enumerate(fp):
pass
num = i+1
print('words contained in the file:',num)
fp.close()
select = input('Select(D/A/L/Q):')
if select == 'D':
print('enter *quit* to exit dictation')
while select == "D":
if li == '':
li = input('Display correct list throughout the dictation?(Y/N)')
#file_choice = input('File version(1/2):')
file_choice = ('漢字と意味.txt')
rep = True
while (rep):
rep = False
file = open(os.path.join(here, file_choice),'r',encoding='utf8')
line = next(file)
for num, aline in enumerate(file, 2):
if random.randrange(num):
continue
line = aline
temp_list = line.split()
for i in range(len(hist)):
if temp_list[1] == hist[i]:
rep = True
print(temp_list[1])
x = input("Answer:")
while x != temp_list[0] and x!='quit':
print("Incorrect")
x = input("Again:")
if x == 'quit':
break
if x == temp_list[0]:
print("Correct!")
hist.append(temp_list[1])
if li == 'Y':
print('words got right:',hist)
if len(hist) == num:
print('all words are dictated')
break
while select == "A":
word = input('hiragana:')
if word == 'quit':
break
tran = input('translation:')
if tran == 'quit':
break
with open(os.path.join(here, '漢字と意味.txt'),'a',encoding='utf8') as file:
file.write('\n'+word+' '+tran)
print('successful')
if select == 'L':
print('=================================')
with open(os.path.join(here, '漢字と意味.txt'),'r',encoding='utf8') as file:
print(file.read())
print('=================================')
exit()