Posted in Python onSeptember 09, 2019
这篇文章主要介绍了python英语单词测试小程序代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
爬取了扇贝英语网,并制作了一个英语单词测试的小程序,还能生成错词本,一起来看下代码吧~
import requests #扇贝网爬虫,获取英语单词 category_res=requests.get('https://www.shanbay.com/api/v1/vocabtest/category/?_=1566889802182') category_json=category_res.json() category_data=category_json['data'] #选择出题范围 for i in range(10): print(str(i+1)+'.'+category_data[i][1]) number=int(input('请选择出题范围:')) url='https://www.shanbay.com/api/v1/vocabtest/vocabularies/' headers={ 'Referer': 'https://www.shanbay.com/vocabtest/', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15' } params={ 'category':category_data[number-1][0], '_': '1566889452889' } res=requests.get(url,headers=headers,params=params) jsonres=res.json() vacabularies=jsonres['data'] knows=[] unknows=[] print() print('以下单词你是否认识?') n=0 z=0 b=open('错词本.txt','a+') b.write('你不认识的单词有:\n') #测试开始,挑选认识的单词 for vacabulary in vacabularies: n=n+1 vacabu=vacabulary['content'] print('第'+str(n)+'个:'+vacabu) index=vacabularies.index(vacabulary) while True: judge=input('认识选Y,不认识选N:') if judge=='Y': knows.append(index) break elif judge=='N': unknows.append(index) z=z+1 b.write(str(z)+'.'+vacabu+'\n') break else: print('请输入Y或者N') print() print('测试结束,以下是测试结果:') print('认识'+str(len(knows))+'个单词,不认识'+str(len(unknows))+'个单词。') print('你可真棒!') print() right=[] wrong=[] #选择正确的词义 b.write('你记错的单词有:\n') m=0 for know in knows: vacabulary_know=vacabularies[know] word=vacabulary_know['content'] print() print(word) definitions=vacabulary_know['definition_choices'] for i in range(4): print(str(i+1)+'.'+definitions[i]['definition']) choice=int(input('单词测试,请选择正确的词义:')) rank=definitions[choice-1]['rank'] if rank==vacabulary_know['rank']: right.append(word) else: wrong.append(word) m=m+1 b.write(str(m)+'.'+word+'\n') print() print('测试结果出来啦!') print('认识的单词里掌握了这几个:') print(right) print() print('没掌握的是这几个:') print(wrong)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。
python英语单词测试小程序代码实例
- Author -
wx5d72071a58c07声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@