Skip to content

Commit e4426f8

Browse files
author
胡耀淇
committed
简陋的版本,完成了最最基本的功能。
1 parent 64c129d commit e4426f8

6 files changed

+189
-26
lines changed

.vscode/settings.json

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"python.pythonPath": "/usr/local/bin/python3"
2+
"python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3"
33
}

Test/Test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import xlwings as xw
2+
import pickle
3+
import os
4+
import math
5+
import copy
6+
wb=xw.Book(r'高中英语单词检索词汇总表(人教版)(必修1至选修8).xlsm')
7+
sht=wb.sheets['Sheet1']
8+
sht2=wb.sheets['Sheet2']
9+
sht3=wb.sheets['Sheet3']
10+
data1=sht.range((1,3),(3000,3)).value#需要背诵的全部单词
11+
data2=sht2.range((1,1),(3000,1)).value#需要背诵的全部单词
12+
data3=sht3.range((1,1),(3000,1)).value#需要背诵的全部单词
13+
for a in range(3000):
14+
print('a:%d' %a)
15+
if data3[a]:
16+
if list(data3[a])[0]=='△':
17+
for b in range(3000):
18+
if data1[b]:
19+
if data1[b].lower()==''.join(list(data3[a])[1:]).lower():
20+
sht.cells(b+1,9).value=1
21+
wb.save()
22+
Binary file not shown.

basic.py

100644100755
Lines changed: 166 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,184 @@
11
import xlwings as xw
22
import pickle
33
import os
4-
wb=xw.Book(r'高中英语单词检索词汇总表(人教版)(必修1至选修8).xlsm')
5-
sht=wb.sheets['Sheet1']
6-
sht2=wb.sheets['Sheet2']
4+
import math
5+
import copy
6+
def clear():os.system('cls')
77
class WordsLevel(object):
8-
wordnum=0
9-
days=0
10-
data=sht2.range((1,1),(3000,3)).value
8+
wordnum=0#总单词数
9+
daygoal=0#每天背诵单词数
10+
basicnum=25#假定单词最大数
11+
data=[]#需要背诵的全部单词
12+
days=0#背诵天数
13+
day=0#处于第几天
14+
remeberenglishwords=[]#储存英文单词计划
15+
remeberchinesewords=[]#储存中文单词计划
16+
wrongenglishwords=[]
17+
wrongchinesewords=[]
18+
def Englishcompare(self,inputword,rightword):
19+
a=0
20+
if inputword.lower()==rightword.lower():
21+
a=1
22+
while rightword.find('(')!=-1:
23+
b=list(rightword)
24+
b.remove('(')
25+
b.remove(')')
26+
if b[0]==' ':
27+
b.pop(0)
28+
if b[-1]==' ':
29+
b.pop(-1)
30+
c=''.join(b)
31+
e=rightword.find('(')
32+
f=rightword.find(')')
33+
g=list(rightword[:e])+list(rightword[f+1:])
34+
g=''.join(g)
35+
if inputword.lower()==c.lower():
36+
a=1
37+
if inputword.lower()==g.lower():
38+
a=1
39+
rightword=c
40+
if rightword.find('=')!=-1:
41+
c=rightword.find('=')
42+
b=list(rightword)
43+
if inputword.lower()==''.lower().join(b[:c]):
44+
a=1
45+
if inputword.lower()==''.lower().join(b[c+1:]):
46+
a=1
47+
return a
48+
def Chinesecompare(self,inputword,rightword):
49+
a=list(inputword)
50+
b=list(rightword)
51+
c=0
52+
for i in range(len(a)):
53+
if a[i]in b:
54+
c+=1
55+
if c>=2:
56+
return 1
57+
else:return 0
58+
def __init__(self):
59+
hasschedule=0
60+
for filename in os.listdir("."):
61+
if filename[-6:]=='pickle':
62+
WordsLevel.Readschedule(WordsLevel)
63+
hasschedule=1
64+
break
65+
if hasschedule == 0 or WordsLevel.days==0 or WordsLevel.wordnum==0:
66+
wb=xw.Book(r'高中英语单词检索词汇总表(人教版)(必修1至选修8).xlsm')
67+
sht=wb.sheets['Sheet1']
68+
sht2=wb.sheets['Sheet2']
69+
WordsLevel.data=sht2.range((1,1),(WordsLevel.basicnum,4)).value
70+
while WordsLevel.data[WordsLevel.wordnum][0]!=None:
71+
WordsLevel.wordnum+=1
72+
#print(WordsLevel.wordnum)
73+
WordsLevel.wordnum -= 1
74+
for b in range(WordsLevel.basicnum-WordsLevel.wordnum-1):
75+
WordsLevel.data.pop()
76+
WordsLevel.data.pop(0)
77+
WordsLevel.setplan(WordsLevel)
78+
else:
79+
WordsLevel.Readschedule(WordsLevel)
80+
def Wordremember(self):
81+
82+
print('少侠,欢迎来到练武场,这是%d次练习,距离大成还需%d次,首先我们练习英文大典之汉英转化,请在中文后输入对应的英文,按回车键提交输入。'%(WordsLevel.day+1,WordsLevel.days-WordsLevel.day))
83+
for a in range(WordsLevel.daygoal):
84+
b=input('%s'%WordsLevel.remeberenglishwords[WordsLevel.day][a][1])
85+
if WordsLevel.Englishcompare(WordsLevel,b,WordsLevel.remeberenglishwords[WordsLevel.day][a][0])==0:
86+
WordsLevel.wrongenglishwords.append(WordsLevel.remeberenglishwords[WordsLevel.day][a])
87+
d=0
88+
while(d!=3):
89+
c=input("招式错误,正确的是%s,再练习三遍,中间以空格相隔,按回车提交。"%WordsLevel.remeberenglishwords[WordsLevel.day][a][0])
90+
c=c.split(' ')
91+
if len(c)<3:
92+
print('要练三遍不准偷懒!!!')
93+
continue
94+
if len(c)>3:
95+
print('说好了三遍,你想走火入魔???!!!')
96+
continue
97+
for i in range(3):
98+
if WordsLevel.Englishcompare(WordsLevel,c[i],WordsLevel.remeberenglishwords[WordsLevel.day][a][0])==1 :
99+
d+=1
100+
else:d=0
101+
102+
clear()
103+
print('少侠,恭喜完成英文大典之汉英转化,接下来首先我们练习英文大典之汉英转化,请在英文后输入对应的中文,按回车键提交输入。')
104+
for a in range(WordsLevel.daygoal):
105+
b=input('%s'%WordsLevel.remeberchinesewords[WordsLevel.day][a][0])
106+
if WordsLevel.Chinesecompare(WordsLevel,b,WordsLevel.remeberenglishwords[WordsLevel.day][a][1])==0:
107+
WordsLevel.wrongchinesewords.append(WordsLevel.remeberchinesewords[WordsLevel.day][a])
108+
d=0
109+
while(d!=3):
110+
c=input("招式错误,正确的是%s,再练习三遍,中间以空格相隔,按回车提交。"%WordsLevel.remeberchinesewords[WordsLevel.day][a][1])
111+
c=c.split(' ')
112+
if len(c)<3:
113+
print('要练三遍不准偷懒!!!')
114+
continue
115+
if len(c)>3:
116+
print('说好了三遍,你想走火入魔???!!!')
117+
continue
118+
for i in range(3):
119+
if WordsLevel.Chinesecompare(WordsLevel,c[i],WordsLevel.remeberchinesewords[WordsLevel.day][a][1])==1 :
120+
d+=1
121+
else:d=0
122+
WordsLevel.day+=1
123+
WordsLevel.Mainmenu(WordsLevel)
124+
WordsLevel.Saveschedule(WordsLevel)
125+
def Mainmenu(self):
126+
'主菜单'
127+
print('1.背单词')
128+
#a=int(input('请输入你要去的地方的方位,按回车键结束!'))
129+
a=int(input('请输入你要去的地方的方位,按回车键结束!'))
130+
if a==1:
131+
WordsLevel.Wordremember(WordsLevel)
132+
def Setremember(self):
133+
'随机生成中英文背诵表'
134+
for a in range(WordsLevel.days):
135+
for b in range(WordsLevel.daygoal):
136+
if len(WordsLevel.data):
137+
WordsLevel.remeberenglishwords[a][b]=WordsLevel.data.pop()
138+
else:
139+
break
140+
a=WordsLevel.daygoal
141+
while a>=0:
142+
if WordsLevel.remeberenglishwords[WordsLevel.days-1][a-1]==None:
143+
WordsLevel.remeberenglishwords[WordsLevel.days-1].pop(a-1)
144+
a-=1
145+
WordsLevel.remeberchinesewords=copy.deepcopy(WordsLevel.remeberenglishwords)
11146
def Bookselect(self):
147+
'选择需要背诵的书籍'
12148
#wb=xw.Book(r'高中英语单词检索词汇总表(人教版)(必修1至选修8).xlsm')
13149
#sht=wb.sheets['Sheet1']
14150
#sht2=wb.sheets['Sheet2']
15151
print('可供选择的书籍有:')
16-
print(sht.range((1,6),(8,6)).value)
152+
#print(WordsLevel.sht.range((1,6),(8,6)).value)
17153
bookname=input('请输入你要背诵的单词书,中间以空格作为分割。(例如:必修1 必修2)').split(' ')
18154
print(bookname)
19155
def setplan(self):
20-
while WordsLevel.data[WordsLevel.wordnum]!=[None,None,None]:
21-
WordsLevel.wordnum+=1
22-
#print(WordsLevel.wordnum)
23-
WordsLevel.days=input('大侠选择的单词共有%d,准备几天结果掉它们?' % WordsLevel.wordnum)
24-
def Saveschedule(self,duixiang):
156+
'建立自己的背诵目标,只运行一次'
157+
a=input('请问少侠是否要挑战三角符号的单词(不推荐)(y or n)(按回车结束输入)')
158+
if a=='n':
159+
b=WordsLevel.wordnum-1
160+
while b>=0:
161+
if(WordsLevel.data[b][3]==1):
162+
WordsLevel.data.pop(b)
163+
b-=1
164+
WordsLevel.wordnum=len(WordsLevel.data)
165+
WordsLevel.daygoal=int(input('少侠选择的单词共有%d,准备一天结果掉几个?' % WordsLevel.wordnum))
166+
WordsLevel.days=math.ceil(WordsLevel.wordnum/WordsLevel.daygoal)
167+
WordsLevel.remeberenglishwords=[[None for i in range(WordsLevel.daygoal)] for i in range(WordsLevel.days)]
168+
WordsLevel.Setremember(WordsLevel)
169+
WordsLevel.Saveschedule(WordsLevel)
170+
def Saveschedule(self):
171+
'保存进度'
25172
file= open('parameter.pickle','wb')
26-
pickle.dump(a,file)
173+
basicnum=[WordsLevel.wordnum,WordsLevel.daygoal,WordsLevel.days,WordsLevel.day]
174+
alldata=[basicnum,WordsLevel.data,WordsLevel.remeberchinesewords,WordsLevel.remeberchinesewords,WordsLevel.wrongchinesewords,WordsLevel.wrongenglishwords]
175+
#print(alldata)
176+
pickle.dump(alldata,file)
27177
file.close()
28178
def Readschedule(self):
29179
with open('parameter.pickle', 'rb') as file:
30180
a=pickle.load(file)
31-
return a
32-
hasschedule=0
181+
WordsLevel.wordnum,WordsLevel.daygoal,WordsLevel.days,WordsLevel.day=a[0]
182+
WordsLevel.data,WordsLevel.remeberenglishwords,WordsLevel.remeberchinesewords,WordsLevel.wrongchinesewords,WordsLevel.wrongenglishwords=a[1],a[2],a[3],a[4],a[5]
33183
a=WordsLevel()
34-
for filename in os.listdir("."):
35-
if filename[-6:]=='pickle':
36-
hasschedule=1
37-
break
38-
if hasschedule == 0:
39-
a.setplan()
40-
a.Saveschedule(a)
41-
else:
42-
a=a.Readschedule()
43-
print(a.days)
184+
a.Mainmenu()

parameter.pickle

1.09 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)