Python 背单词小程序

源代码:

import random
def remember(answer,result,aquestion,aw,wrong_answer):
    while answer!=-1:
        x=random.randint(0,len(result)-1)
        if x not in aquestion:
            aquestion.append(x)
            print('中文:'+result[x][1])
            answer=input('英文(输入‘-1’结束):')
            while aw==0:
                if answer==result[x][0]:
                    print('-----------------正确-----------------')
                    print('\n')
                    aw=1
                if answer!=result[x][0]:
                    print('-----------------错误-----------------')
                    if [result[x][0],result[x][1]] not in wrong_answer:
                        wrong_answer.append([result[x][0],result[x][1]])
                    answer=input('重新输入(‘0’查看答案):')
                    if answer=='0':
                        print('-----------------答案-----------------')
                        print(result[x][0])
                        print('\n')
                        aw=1
            aw=0
        if len(aquestion)==len(result):
            if len(wrong_answer)!=0:
                result=wrong_answer
                wrong_answer=[]
                aquestion=[]
                print('错误单词如下:')
                print(result)
                print('开始复习错误单词!!!')
                print('\n')
                remember(answer,result,aquestion,aw,wrong_answer)
            answer=-1
    
with open('C:/Users/F.S.Z/Desktop/单词文本.txt') as f:
    result=[]
    aquestion=[]
    f=f.read()
    a=f.split('\n')
    answer=0
    aw=0
    wrong_answer=[]
    for i in a:
        b=str(i).split(',')
        for j in b:
            c=str(j).split('/')
            result.append(c)
    remember(answer,result,aquestion,aw,wrong_answer)
    print('复习完毕!!')
        

单词文本:
Python 背单词小程序_第1张图片
注意文本格式,逗号是汉字的逗号

你可能感兴趣的:(Python 背单词小程序)