溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

python英語(yǔ)單詞測(cè)試小程序

發(fā)布時(shí)間:2020-07-02 18:56:37 來(lái)源:網(wǎng)絡(luò) 閱讀:348 作者:wx5d72071a58c07 欄目:編程語(yǔ)言

博主爬取了扇貝英語(yǔ)網(wǎng),并制作了一個(gè)英語(yǔ)單詞測(cè)試的小程序,還能生成錯(cuò)詞本,一起來(lái)看下代碼吧~

import requests

#扇貝網(wǎng)爬蟲(chóng),獲取英語(yǔ)單詞
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('請(qǐng)選擇出題范圍:'))

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('以下單詞你是否認(rèn)識(shí)?')
n=0
z=0

b=open('錯(cuò)詞本.txt','a+')
b.write('你不認(rèn)識(shí)的單詞有:\n')

#測(cè)試開(kāi)始,挑選認(rèn)識(shí)的單詞
for vacabulary in vacabularies:
    n=n+1
    vacabu=vacabulary['content']
    print('第'+str(n)+'個(gè):'+vacabu)
    index=vacabularies.index(vacabulary)

    while True:
        judge=input('認(rèn)識(shí)選Y,不認(rèn)識(shí)選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('請(qǐng)輸入Y或者N')
print()           
print('測(cè)試結(jié)束,以下是測(cè)試結(jié)果:')
print('認(rèn)識(shí)'+str(len(knows))+'個(gè)單詞,不認(rèn)識(shí)'+str(len(unknows))+'個(gè)單詞。')
print('你可真棒!')
print()

right=[]
wrong=[]

#選擇正確的詞義
b.write('你記錯(cuò)的單詞有:\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('單詞測(cè)試,請(qǐng)選擇正確的詞義:'))
    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('測(cè)試結(jié)果出來(lái)啦!')

print('認(rèn)識(shí)的單詞里掌握了這幾個(gè):')
print(right)
print()
print('沒(méi)掌握的是這幾個(gè):')
print(wrong)
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI