import easygui as eg
import random
import time
def make_button(ranswer,mean_list): #生成选项
global style
number0 = mean_list.index(ranswer) #计算出正确翻译 ranswer 在翻译列表 mean_list 里的索引
number1 = random.randint(0,len(mean_list) - 1) #生成出除 number0 之外的随机索引
while number1 == number0:
number1 = random.randint(0,len(mean_list) - 1)
number2 = random.randint(0,len(mean_list) - 1) #生成除 number0 和 number1 之外的随机索引
while number2 == number0 or number2 == number1:
number2 = random.randint(0,len(mean_list) - 1)
button = [mean_list[number0],mean_list[number1],mean_list[number2]] #生成答案与假答案的混合列表
button_list = random.sample(range(0,3),3) #生成将 button 列表的引用索引打乱后的顺序
button_dict = {i[1] if style == 0 else button[int(i[0])]:button[int(i[0])] for i in zip([str(each) for each in button_list],["A","B","C"])} #合成随机提问选项
return button_dict
def check_answer(I,first_know,i): #检查答案是否合法
global answer
global style
question_style = 1 if I == 1 and first_know[i] == True else 0 #判断题目类型:0 是选择题, 1 是判断题
alpha_list = ["A","B","C"] if question_style == 0 else ["A","B"] #判断题目前都有哪些序号
if style == 0:
while answer.isspace() or answer == "": #规范输入
answer = input("请选择正确的一项:")
while answer.strip().upper() not in alpha_list:
answer = input("请选择正确的一项:")
else:
pass
answer = answer.strip() #去掉选项两边可能存在的空格
answer = answer.upper() #将用户输入的选项变成大写
def question(button_dict,guess,choose): #打印题目
global style
global answer
if choose == 0: #打印选择意思题
if style == 0:
for each in button_dict.items():
print(each[0],".",each[1])
else:
answer = eg.buttonbox(f"请选择单词 {guess} 的意思下方选项中的最贴切的一项:",choices = tuple([each[1] for each in button_dict.items()]))
elif choose == 1:
if style == 0:
print(f"单词:{guess}")
for each in zip(["A","B"],["会","不会"]):
print(each[0],".",each[1])
else:
answer = eg.buttonbox(f"单词 {guess} 请节和你的自身情况给予回答:",choices = ("会","不会"))
def check_first_question(button_dict,answer,ranswer):
print(button_dict,answer)
global style
if style == 0:
if button_dict.get(answer) == ranswer: #如果猜对
return True
else:
return False
else:
if button_dict.get(answer) == ranswer: #如果猜对
return True
else:
return False
def over(word_list,now_heavy_list,heavy_list): #更新是否全部背完的列表
finish = ["" for i in range(len(word_list))]
for each in zip(now_heavy_list,heavy_list,range(len(word_list))):
if each[0] >= each[1] or now_heav_list[each[2]] >= max_heav:
finish[each[2]] = True
else:
finish[each[2]] = False
return finish
word_list = ["nice","good","wow","cow","car","jar","mud","you","human","wine","school","life"
,"writer","wife","oil","ink","oil painting","chinese ink painting","unhappy"] #可自行添加
mean_list = ["棒的","好的","表示吃惊","奶牛","车","坛子","泥土","你","人类","红酒","学校","生活"
,"作家","妻子","油","墨水","油画","中国水墨画","不高兴的"] #可自行添加
if len(word_list) != len(mean_list): #如果两个列表长度不等
print("错误:请重新设置列表 mean_list 和 word_list 它们的长度必须一致!")
if len(mean_list) < 3 or len(word_list) < 3: #如果列表的元素小于三个
print("错误:列表里的元素不能少于 3 个!")
while len(mean_list) < 3: #合法输入
mean_list = input("请输入 mean_list 列表的元素(用逗号分隔,不用加方括号):").split(sep = ",")
if len(mean_list) < 3: #如果列表的元素小于三个
print("错误:列表里的元素不能少于 3 个!")
while len(word_list) != len(mean_list) or len(word_list) < 3: #合法输入
word_list = input("请输入 word_list 列表的元素(用逗号分隔,不用加方括号):").split(sep = ",")
if len(word_list) != len(mean_list): #如果两个列表长度不等
print("错误:请重新设置列表 mean_list 和 word_list 它们的长度必须一致!")
if len(mean_list) < 3 or len(word_list) < 3: #如果列表的元素小于三个
print("错误:列表里的元素不能少于 3 个!")
jian = 1 #设置每道题之间是否插入间隔#######################可自行更改
heavy = 2 #设置默认每个要背出多少才算背会#######################可自行更改
heavy_list = [heavy for i in range(len(word_list))] #默认每个要背出的次数列表
now_heavy = 0 #设置每个默认已背出的次数#######################可自行更改
now_heavy_list = [now_heavy for i in range(len(word_list))] #默认每个已背出的次数列表
max_heav = 3 #设置每个单词最多的背诵次数#######################可自行更改
now_heav = 0 #设置每个默认已背的次数#######################可自行更改
now_heav_list = [now_heav for i in range(len(word_list))] #默认每个已背的次数列表
first_know = ["" for i in range(len(word_list))] #设置第一次就会的单词
finish = over(word_list,now_heavy_list,heavy_list)
print("""0:IDLE
1:图形界面""")
style = int(input("请输入要用哪个模式:"))
time_start = time.time() #开始计时
if style == 0:
I = 0
while not all(finish): #如果没有结束背诵任务
i_list = random.sample(range(len(word_list)),len(word_list)) #不重复的随机抽选要提问的单词的先后顺序
for i in i_list:
if finish[i] == False: #如果这个单词还没有背完
ranswer = mean_list[i] #设置正确的翻译
guess = word_list[i] #设置要提问的单词
button_dict = make_button(ranswer,mean_list)
#打印题目部分
if I == 1 and first_know[i] == True:
question(button_dict,guess,choose = 1) #打印判断题
else:
question(button_dict,guess,choose = 0) #打印选择意思题
#向用户提问选项部分
if I == 1 and first_know[i] == True: #如果是判断题
answer = input("请节和你的自身情况给予回答:")
else: #如果是选择题
answer = input(f"请选择单词 {guess} 的意思在上方选项中的最贴切的一项:")
check_answer(I,first_know,i) #强制用户合法输入
#判断部分
now_heav_list[i] += 1
if I == 1 and first_know[i] == True: #如果是判断题
if answer == "A":
question(button_dict,guess,choose = 0) #提选择题
answer = input(f"请选择单词 {guess} 的意思在上方选项中的最贴切的一项:")
check_answer(I,first_know,i) #强制用户合法输入
if check_first_question(button_dict,answer,ranswer): #如果猜对
now_heavy_list[i] += (heavy_list[i] - now_heavy_list[i]) #直接将此单词设为会了
print("答对了!")
else: #如果没猜对
print("答错了!")
print(f"记住了!单词 {guess} 的中文是 {ranswer} !")
elif answer == "B":
print(f"记住了!单词 {guess} 的中文是{ranswer}!")
else:
if check_first_question(button_dict,answer,ranswer): #如果猜对
now_heavy_list[i] += 1 #增加答对的次数
if I == 0:
first_know[i] = True #设置此单词第一次提问时就会了
print("答对了!")
else: #如果没猜对
print("答错了!")
print(f"记住了!单词 {guess} 的中文是 {ranswer} !")
#遮挡部分
if jian:
t.sleep(1.5)
for i in range(70): #打印间隔
print(f"{'|':^156}")
print()
#更新 是否结束背诵任务
finish = over(word_list,now_heavy_list,heavy_list)
if all(finish): #如果都结束了,退出循环
break
I += 1 #更新目前提的遍数
#计算尾部空格数量部分
max_long_word_length = len(max(word_list,key = lambda x : len(x))) #计算出单词列表 word_list 中最长的一个单词的长度
word_with_space = [(max_long_word_length * 3) - len(each) for each in word_list] #计算出每个单词后面跟着的空格数量列表# 3 是可更改的,最小为 2
time_end = time.time() #结束计时
time_c= time_end - time_start #运行所花时间
time_c= round(time_c)#四舍五入
#向用户输出结尾部分
print("\n" * 3) # 3 是可更改的
print(f"你这次学习时间 {time_c} 秒")
print("你已背完了这些单词:{}!".format(",".join(word_list)))
#输出每个单词的正确率部分
True_list = [f"{now_heavy_list[i] / (now_heav_list[i]) if (now_heav_list[i]) > 0 else 1:.1%}" for i in range(len(word_list))] #每个单词的正确率列表
print("你做题时对这些单词分别的正确率:")
for each in zip(word_list,True_list,range(len(word_list))):
space = " " * word_with_space[each[2]]
print(f"单词{each[0]}{space}正确率:{each[1]}")
else:
I = 0
while not all(finish): #如果没有结束背诵任务
i_list = random.sample(range(len(word_list)),len(word_list)) #不重复的随机抽选要提问的单词的先后顺序
for i in i_list:
if finish[i] == False: #如果这个单词还没有背完
ranswer = mean_list[i] #设置正确的翻译
guess = word_list[i] #设置要提问的单词
button_dict = make_button(ranswer,mean_list)
#打印题目部分
if I == 1 and first_know[i] == True:
question(button_dict,guess,choose = 1) #打印判断题
else:
question(button_dict,guess,choose = 0) #打印选择意思题
#判断部分
now_heav_list[i] += 1
if I == 1 and first_know[i] == True: #如果是判断题
if answer == "会":
question(button_dict,guess,choose = 0) #提选择题
if check_first_question(button_dict,answer,ranswer): #如果猜对
now_heavy_list[i] += (heavy_list[i] - now_heavy_list[i]) #直接将此单词设为会了
eg.msgbox("答对了")
else: #如果没猜对
eg.msgbox("答错了!")
eg.msgbox(f"记住了!单词 {guess} 的中文是 {ranswer} !")
elif answer == "不会":
eg.msgbox(f"记住了!单词 {guess} 的中文是{ranswer}!")
else:
if check_first_question(button_dict,answer,ranswer): #如果猜对
now_heavy_list[i] += 1 #增加答对的次数
if I == 0:
first_know[i] = True #设置此单词第一次提问时就会了
eg.msgbox("答对了!")
else: #如果没猜对
eg.msgbox("答错了!")
eg.msgbox(f"记住了!单词 {guess} 的中文是 {ranswer} !")
#更新 是否结束背诵任务
finish = over(word_list,now_heavy_list,heavy_list)
if all(finish): #如果都结束了,退出循环
break
I += 1 #更新目前提的遍数
#计算尾部空格数量部分
max_long_word_length = len(max(word_list,key = lambda x : len(x))) #计算出单词列表 word_list 中最长的一个单词的长度
word_with_space = [(max_long_word_length * 3) - len(each) for each in word_list] #计算出每个单词后面跟着的空格数量列表# 3 是可更改的,最小为 2
time_end = time.time() #结束计时
time_c= time_end - time_start #运行所花时间
time_c= round(time_c)#四舍五入
#向用户输出结尾部分
eg.msgbox(f"你这次学习时间 {time_c} 秒")
eg.msgbox("你已背完了这些单词:{}!".format(",".join(word_list)))
#输出每个单词的正确率部分
True_list = [f"{now_heavy_list[i] / (now_heav_list[i]) if (now_heav_list[i]) > 0 else 1:.1%}" for i in range(len(word_list))] #每个单词的正确率列表
eg.msgbox("你做题时对这些单词分别的正确率:")
for each in zip(word_list,True_list,range(len(word_list))):
space = " " * word_with_space[each[2]]
eg.msgbox(f"单词{each[0]}{space}正确率:{each[1]}")
#h