python

前提准备

  1. 安装好python及其环境
  2. 安装好Oracle数据库
  3. python中安装好cx_Oracle包,且能与数据库正常联立交互

注: 前提准备部分的内容不做描述,百度均有教程

步骤:

第一步:在oracle中创建以下表:

下面展示 建表语句

--ID_FLAG表是用以记录单词进度
create table ID_FLAG
(id_value    NUMBER(5),insert_time VARCHAR2(50)
)-- EXAM_FUN2表用以记录模块2中测验的结果
create table EXAM_FUN2
(id            NUMBER(5),word          VARCHAR2(100),chinese_value VARCHAR2(1024),insert_time   VARCHAR2(50),isright       VARCHAR2(10)
)-- ALL_WORDS表是单词的记录储存表
create table ALL_WORDS
(id            NUMBER(5) not null,word          VARCHAR2(100),chinese_value VARCHAR2(1024)
)--
-- 这是用以储存自已写的例句表
create table EXAMPLE_SENTENCE_TABLE
(id_scope         VARCHAR2(10),example_sentence VARCHAR2(500),insert_time      VARCHAR2(50)
)
第二步:运行脚本向数据库中导入文件里的单词数据

下面这个是单词的txt文件:
链接: https://pan.baidu.com/s/1Ga2sHQJrpg3LGvLDt_i4vQ?pwd=1234

这是导入数据库的脚本代码:
:代码中的数据库账号密码端口以及文件路径等信息需要自行修改。

import cx_Oracle as cxdef condba():global connusername = 'briup'  #数据库的账号        password = 'briup'  #数据库的密码     host = '127.0.0.1:1521/XE' conn = cx.connect(username,password,host)cursor = conn.cursor()return cursordef run(con):'''准备写一个方法可以读取指定文件夹中的文件,并将文件名和指定数放在两个list中'''#============拆分文件模块开始==============#print('=======进入run方法========')#print(content)list_id=[]list_word=[]list_chineseValue=''strlist = con.split()#print(strlist)list_id = strlist[0]list_word = strlist[1]list_len = len(strlist)#print(list_len)if list_len == 3:list_chineseValue = strlist[2]else:i = 2temp_str=''while i < list_len:temp_str = temp_str+str(strlist[i])i = i+1#print(temp_str)list_chineseValue=temp_str#print('==========拆分结束=========')# #========已将文件拆到三个列表中========# #============拆分文件模块结束==============   return   list_id,list_word,list_chineseValueif __name__ == '__main__':try:print('==========开始插入数据=========')dba = condba()filepath = r'D:\记得修改路径\1.txt'  fp = open(filepath,'r',encoding='UTF-8')#读取文件内容content = fp.readlines()#print(content)delete_sql = "truncate table all_words"dba.execute(delete_sql)print('all_words原数据已删除')for con in content:id,word,cv = run(con)insert_sql = str_temp = "insert into all_words values('%s','%s','%s')" % (id,word,cv)#print(insert_sql)dba.execute(insert_sql)     except Exception as e:conn.rollback()print(e)finally:conn.commit()conn.close()fp.close()print('==========数据插入结束=========')

出现以下显示时表明数据插入完成。
:其实若愿意的话,也可以将前面的建表语句放到后面的数据插入脚本中一次性执行,写个str字符串,将sql放进去后,用ora.execute(str)执行后再将其commit即可,此处没写进去是因为在plsql中用习惯了,方便修改。

数据插入完成后,便可以执行以下python脚本了

import cx_Oracle as cx
import randomdef condba():global connusername = 'briup'password = 'briup'host = '127.0.0.1:1521/XE'conn = cx.connect(username,password,host)cursor = conn.cursor()return cursor'''分4种模式:1.第一种按顺序五个五个出现word和cv  ,可以输入数字5尝试写例句用以加强记忆2.第二种里共有三种测试方式,前两种只出现翻译,填写word,并进行检测是否匹配,第1中是每15个进行一次检测,第2种是从开头一直检测到已学部分,第3种是有单词有翻译,进行选择,所有检测的结果会记录在表exam_fun2中3.第三种将所有false的进行再次复习与测验,1是进行复习,2是对二模式中测验错误的进行再次测验,若对了会更新记录4.将复习的表进行重置 --保留表中id = 1的值,方便重置后方法的运行,一切重新开始
'''def fun1(ora):count = 1print('您已选择第一种模式:')id_sql = "select * from (select * from  id_flag  order by id_value desc) where rownum = 1"ora.execute(id_sql)result = ora.fetchall()#print(result[0][0])order = '0'      #'0'继续学习,stop()结束学习id = result[0][0]  #读取数据库中表id_flag中最后一次记录的id值while id <= 5384:if(count == 4):print('已满15个,是否进行一次测验? Y/N')isCheck = input('请输入:')while isCheck:if isCheck == 'Y':exam3(ora)break  elif isCheck == 'N':print('继续学习')breakelse:print('请不要输入除了Y或N以外的内容:')isCheck = input('请输入:')count = 1  if order == 'stop()':breakelif order == '5':print('请写您的例句:',end='')example_sentence = input()id_str = '%d~%d' % (id-5,id)ex_sql = "insert into example_sentence_table values('%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'))" % (id_str,example_sentence);ora.execute(ex_sql)conn.commit()elif order == '0':print('===========================分隔符===========================')count = count + 1strsql = "select word,chinese_value from all_words where id >= %d and id < %d" % (id,id+5)#print(strsql) ora.execute(strsql)strsql_result = ora.fetchall()for v in strsql_result:#print(v[1])a ="%s :  %s" % (v[0],v[1])print(a)else:print('请输入正确的指令!')  insertId_sql = "insert into id_flag values(%d,to_char(sysdate,'yyyymmdd hh24:mi:ss'))" % (id)ora.execute(insertId_sql)conn.commit()  #每学习一次就要记录一次,方便方法2在测验的时候进行读取id范围id = id+5print('请输入指令:--stop()--退出,--5--自写例句,--0--下一个')print('===========================分隔符===========================')order = input('请输入:')print('第一种模式结束')#2.第二种只出现cv,填写word,并进行检测是否匹配,从id_flag表中读取id进行
def fun2(ora):print('*******模块2测验开始*******')print('**********分界线************')print('请输入数字1对已学进行阶段测验')print('请输入数字2对已学进行全面测验')print('请输入数字3对已学进行新的测验')print('**********分界线************')print('请输入一个数字或输入quit退出:')num = input('请输入:')while num != 'quit':if num == '1':           exam1(ora)elif num == '2':exam2(ora)elif num == '3':exam3(ora)else : print('输入有误!')print('**********分界线************')print('请输入数字1对已学进行阶段测验')print('请输入数字2对已学进行全面测验')print('请输入数字3对已学进行新的测验')print('**********分界线************')print('请输入一个数字或输入quit退出:')num = input('请输入:')  print('*****阶模块2测验结束*****')def exam1(ora):print('*****阶段性测验开始*****')str_sql = "select min(id_value),max(id_value) from (select * from  id_flag  order by id_value desc) where rownum < 5 order by 1" #读取记录表中的最后两条记录的id值ora.execute(str_sql)result = ora.fetchall()#print(result)id1 = result[0][0]id2 = result[0][1]str_sql2 = "select * from all_words where id >= %d and id <= %d" % (id1,id2+5)#print(str_sql2)ora.execute(str_sql2)sql2_cv = ora.fetchall()#print(sql2_cv)for t in sql2_cv:print(t[2])print('请输入对应的word值:')word = input('请输入:')if(word == t[1]):sql_check = "insert into exam_fun2 values(%d,'%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'),'true')" % (t[0],t[1],t[2])print('correct!')else:sql_check = "insert into exam_fun2 values(%d,'%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'),'false')" % (t[0],t[1],t[2])print('wrong! the correct answer is :'+ t[1])#print(sql_check)print('**********************分隔符*****************************')ora.execute(sql_check)conn.commit()print('*****阶段性测验结束*****')def exam2(ora):print('*****整体测验开始*****')str_sql2 = "select * from all_words where id <= (select max(id_value) from id_flag a)"#print(str_sql2)ora.execute(str_sql2)sql2_cv = ora.fetchall()#print(sql2_cv)for t in sql2_cv:print(t[2])print('请输入对应的word值:')word = input('请输入:')if(word == t[1]):sql_check = "insert into exam_fun2 values(%d,'%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'),'true')" % (t[0],t[1],t[2])print('correct!')else:sql_check = "insert into exam_fun2 values(%d,'%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'),'false')" % (t[0],t[1],t[2])print('wrong! the correct answer is :'+ t[1])#print(sql_check)print('**********************分隔符*****************************')ora.execute(sql_check)conn.commit()print('*****整体测验结束*****')def exam3(ora):print('*****选汉语测验开始*****')str_sql = "select min(id_value),max(id_value) from (select * from  id_flag  order by id_value desc) where rownum < 5 order by 1" #读取记录表中的最后两条记录的id值ora.execute(str_sql)result = ora.fetchall()#print(result)id1 = result[0][0]id2 = result[0][1]str_sql2 = "select * from all_words where id >= %d and id <= %d" % (id1,id2)  #获取最后两个id值#print(str_sql2)ora.execute(str_sql2)sql2_cv = ora.fetchall()#print(sql2_cv)value = {} #将单词和翻译放在字典中value2 = [] #但翻译放在字典中并序号,方便下面抽取for t in sql2_cv:value[t[1]] = t[2]   # 将这十几个里面抽取三个,与当前选择的值放在一起组成选项value2.append(t[2])#print(random.sample(value2, 3))temp = []new_temp = []for t in sql2_cv:temp = value2.copy() #将所有的翻译给复制到一个临时列表temp中temp.remove(t[2])  #这临时列表中将当前的单词翻译删掉new_temp = random.sample(temp,3)  #在没有当前翻译的剩下值中随机筛选3个组成新的列表new_temp.append(t[2])       #将当前单词的翻译添加进去new_temp = random.sample(new_temp,len(new_temp)) #再将组好的这个新列表进行随机排列print(t[1])count = 1for ft in new_temp:print(count,end='')print(' : ',end='')print(ft)count = count + 1        print('请从上列选项中选择对应的选项:')num = input('请输入选项(1~4)或者quit退出:')flag = 1while flag == 1 and num != 'quit':num = int(num) - 1if num >= 0 and num <= 3 :flag = 0else:print('您输入的值不在1~4之间,请重新输入!')num = input('请输入选项(1~4)或者quit退出:')#num = int(num) - 1if  num == 'quit':breakelif(new_temp[num] == t[2]):sql_check = "insert into exam_fun2 values(%d,'%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'),'true')" % (t[0],t[1],t[2])print('correct!')else:sql_check = "insert into exam_fun2 values(%d,'%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'),'false')" % (t[0],t[1],t[2])print('wrong! the correct answer is :')print(t[2])#print(sql_check)print('**********************分隔符*****************************')ora.execute(sql_check)conn.commit()print('*****选汉语测验结束*****')def fun3(ora):print('*****错重复习开始*****')err_sql  = " select count(*) \from exam_fun2 a ,(select  word,max(insert_time) as max_time from exam_fun2  group by word) b \where a.word = b.word \and a.insert_time = b.max_time  \and a.isright = 'false'\order by insert_time desc "ora.execute(err_sql)err_count = ora.fetchall()print('**********分界线************')if err_count:print('已积累错误个数:',end='')print(err_count[0][0])print('请输入数字1对错误进行再次复习')print('请输入数字2对复习进行再次测验')print('**********分界线************')print('请输入选择或者quit退出:')num = input('请输入:')while num != 'quit':if num == '1':print('**********分界线************')print('您输入的是1,开始对错误进行复习')str_sql = " select a.* \from exam_fun2 a ,(select  word,max(insert_time) as max_time from exam_fun2  group by word) b \where a.word = b.word \and a.insert_time = b.max_time  \and a.isright = 'false'\order by insert_time desc "     #读取测验表中的测验错误的单词ora.execute(str_sql)result = ora.fetchall()for v in result:a ="%s :  %s" % (v[1],v[2])print(a)print('**********分界线************')elif num == '2':print('**********分界线************')print('您输入的是2,开始对错误进行检验')str_sql = " select a.* \from exam_fun2 a ,(select  word,max(insert_time) as max_time from exam_fun2  group by word) b \where a.word = b.word \and a.insert_time = b.max_time  \and a.isright = 'false'\order by insert_time desc "#print(str_sql)ora.execute(str_sql)sql_cv = ora.fetchall()#print(sql_cv)for t in sql_cv:print(t[2])print('请输入对应的word值:')word = input('请输入:')if(word == t[1]):sql_check = "insert into exam_fun2 values(%d,'%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'),'true')" % (t[0],t[1],t[2])print('correct!')else:sql_check = "insert into exam_fun2 values(%d,'%s','%s',to_char(sysdate,'yyyymmdd hh24:mi:ss'),'false')" % (t[0],t[1],t[2])print('wrong! the correct answer is :'+ t[1])#print(sql_check)print('**********分界线************')ora.execute(sql_check)conn.commit()else:print('输入有误,请重新输入!')print('**********分界线************')print('请输入数字1对错误进行再次复习')print('请输入数字2对复习进行再次测验')print('**********分界线************')print('请输入数字选择或者quit退出:')num = input('请输入:')  print('*****错重复习结束*****')def fun4(ora):delete_exam_fun2 = 'delete from exam_fun2 where id > 1'delete_id_flag = 'delete from id_flag where id_value > 1'ora.execute(delete_exam_fun2)ora.execute(delete_id_flag)conn.commit()print('表中记录已重置')if __name__ == '__main__':ora = condba()print("*****请输入指令1或者2或者3或者4,输入exit()退出:*****")print('1. 开始学习单词')print('2. 来一次小测验')print('3. 复习一下上次测验的错误')print('4. 记录重置')print("********************分界线*********************")print('请输入一个选项:')str = input('请输入:')while str != 'exit()':#print(str)if str == '1':fun1(ora)elif str == '2':fun2(ora)elif str == '3':fun3(ora)elif str == '4':fun4(ora)else:print('您输入的选项无效,请重新输入!')str = input('请输入:')continueprint("*****请输入指令1或者2或者3或者4,输入exit()退出:*****")str = input('请输入:')print('bye')conn.close()

这里一共写了四个小功能,分为1,2,3,4四个选项:



第一个功能是直接显示单词与翻译,每五个为一组,按0进行下一组,按5可以对当前的单词自写例句,例句会保存在表EXAMPLE_SENTENCE_TABLE中。满15个就进行一次小测验,结果无论对错都会将其记录在表exam_fun2中,方便后面进行复习和再检测,输入stop()进行退出第一种模式。


第二个功能是测验功能,分三种:


第一种其实就是在1模式中的小测验,第二种是从第一个单词一直到你所学的单词为止全部进行一次测验。这前两种都是根据翻译写单词,第三种是根据单词选择翻译,有四种选项,正确答案是其中的一个。


第三个功能是将前面测验错误的进行重新学习与测验,当重新测验正确后,再下次学习错误单词时便不会再计入内。


第四个功能是将所有学习过的记录,或者错误的记录全部清除掉,一切重新开始,因此便可以进行重复学习

自此便是全部的功能,后续还将添加阅读题,以及对应的题目讲解等功能。
:本脚本的编写环境均由vscode所实现。

用python实现背单词的小脚本系统相关推荐

  1. 用Python编写背单词的小程序

    最近在准备一个成人学士学位的英语考试(长春工业大学计算机专业本科),需要背一些常用的词汇和短语.不愿动笔写,那就用Python编一个自动浏览的小程序,实现这个功能. 操作系统:Mac OS IDE: ...

  2. python语言与系统设计 大作业——背单词的小软件

    (一)需求和规格说明 问题描述: 这是一款帮助学生背单词的小软件.建立单词库: 第一个功能是学生帮助学生记单词,会显示单词库中单词的拼写.音标.词性.中文翻译,学生可以选择中途退出,再次进入的时候,可 ...

  3. python单词软件哪个好_利用Python分析背单词软件的惊人真相

    摘要:利用python分析背单词软件,揭秘你不知道的惊人真相 0×00 前言 你想知道背单词软件有大概多少人注册第一天都没有背完嘛 你想知道背单词软件这么火,这么多人在使用,真的有多少人真的在背诵嘛 ...

  4. 微信背单词类小程序,小鸡单词源码下载,打卡微信小程序

    微信背单词类小程序,小鸡单词源码下载,微信小程序开发学习案例,小程序开发教程.一个用来背单词每天打卡的微信小程序,还有词汇测试,包含多种词库后台由腾讯云wafer解决方案. 前段时间开始学做微信小程序 ...

  5. python写背单词软件_python背单词小程序

    import random as t #创建单词序列 words=("easy","difficult","answer","co ...

  6. python写背单词软件_python实现屏保程序(适用于背单词)

    今天要给大家分享的是一款自己写的屏保程序,大学大家最头疼的就是四六级的考试了,上次考试做阅读的时候,情不自禁的发呆,想着如果我能在电脑上写一个屏保程序,那么就可以天天记单词了! 开始 首先:我们使用的 ...

  7. python编写背单词程序

    目录 1 功能介绍 2 文件准备 3 源码 一年多前初学python时写的代码,这里分享给大家. 1 功能介绍 首先运行程序,进入欢迎界面.如下图,界面是一个小方框,可以选择词库,默认是六级词库. 选 ...

  8. 新技能get!用 Python 高效背单词!

    背景 作为一个程序员,经常需要阅读英文论文.文档.书籍.对于一些基础不好的同学来说,最主要的拦路虎是英语单词.计算机类文档不同于小说,其语法.句式都比较简单,可以说只要词汇量有了,阅读就很简单. 如果 ...

  9. Python制作背单词exe

    使用python编写的背单词程序,可以更快捷,更环保的背单词 以8上英语第8单元的前20个单词为例: import random                   #导入随机库 a = {'1': ...

最新文章

  1. c语言程序设计 中南大学,中南大学-C语言程序设计试卷.docx
  2. 一个奇怪的异常,帮忙看一下
  3. 【myeclipse】java.lang.NullPointerException at com.genuitec.eclipse.ast.deploy.core.Deployment
  4. jsp form提交到后台中文乱码_JSP与servlet之间的数据传递
  5. Codeforces Round #533 (Div. 2) 部分题解A~D
  6. VisualStudioCode常用快捷键
  7. EF中CodeFirst中实体变化的处理方式
  8. WINDOWS用VS2010开发NPAPI插件步骤
  9. 【协同任务】基于matlab多无人机协同任务【含Matlab源码 1273期】
  10. Maple公式推导教程
  11. Vue基础1-如何创建一个vue实例
  12. 如何将Excel的单元格设置成下拉选项?-excel设置下拉菜单
  13. 基于Python网络爬虫的小说网站数据分析
  14. 无法获取链接服务器 (null) 的 OLE DB 访问接口 SQLNCLI10 的架构行集
  15. 要么励志故事:要么孤独,要么庸俗
  16. 投影html连接电脑,电脑如何链接投影仪_台式电脑主机怎么连接投影仪-win7之家...
  17. FF首次适应算法与BF最佳适应算法(C++实现)
  18. oracle税则的优先级,Oracle EBS r12财务模块
  19. 高中教学有计算机课吗,高中计算机课教学的思考
  20. MEMS加速度计核心简介

热门文章

  1. 2023计算机毕业设计SSM最新选题之java乡村疫情防控管理系统37804
  2. 天天使用电脑的人要注意哪些?
  3. 利用windows优化大师,将cmd加入鼠标右键菜单
  4. MySQL 三万字精华总结 + 面试100 问,和面试官扯皮绰绰有余(收藏系列)
  5. java flv转mp3_用java程序调用ffmpeg执行视频文件格式转换flv
  6. Vue 调用PC摄像头拍照
  7. 京东一小伙一年输出20篇专利,其实你也可以
  8. RTP音频流分析以及乱序问题的解决方法(二)
  9. 【强化学习】小项目分析:DQN玩游戏2048
  10. XCP实战系列介绍14-基于Vector_Davinci工具的XCP配置介绍(三)