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/',
}
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英语单词测试小程序
文章源于:http://hbruida.cn/article/gipgoe.html