import random as t
words=('easy','difficult','answer','continue')
zi=('容易','困难','回答','继续')
hanzi={'easy':'容易','difficult':'困难','answer':'回答','continue':'继续','blue':'蓝色'}
yin={'容易':'easy','困难':'difficult','回答':'answer','继续':'continue','蓝色':'blue'}
def jiemain():
print("""
欢迎来到背单词
--------------------------------
1、English——》汉语
2、汉语——》English
3、单次列表
4、退出系统
""")
def yyihan():
n=0
m=0
su=0
iscontinue='y'
while iscontinue=='y'or iscontinue=='Y':
word=t.choice(words)
print('随机生成单词')
print('>--->'+word)
guess=input('\n输入汉语:').strip()
while guess!=hanzi[word]:
print('sorry,error')
n=n+1
print('\n-->right is %.2f%%'%(100*m/(n+m)))
guess=input('continue:').strip()
if guess==hanzi[word]:
print('right')
m=m+1
print('\n-->right:%.2f%%'%(100*m/(n+m)))
iscontinue=input('\nn\是否继续(Y/N):')
def hanyiy():
n=0
m=0
iscontinue='y'
while iscontinue=='y' or iscontinue=='Y':
word=t.choice(zi)
print('>-->'+word)
guess=input('please:').strip()
if guess!=yin[word]:
print('error')
n+=1
print('正确率为%.2f%%'%(100*n/(n+m)))
guess=input('continue:').strip()
elif guess==yin[word]:
print('right')
m+=1
print('正确率为%.2f%%'%(100*m/(n+m)))
iscontinue=input('\nn\是否继续(Y/n):')
def lib():
print('************')
print('\n')
for i in range(len(words)):
print(words[i],' ',zi[i],'\n')
print('\n')
print('***********')
a=input('输入4背单词结束———》:')
while True:
jiemain()
a=int(input('\n\n\n选择需要进行的操作(1/2/3/4):'))
if (a==1):
yyihan()
elif (a==2):
hanyiy()
elif (a==3):
lib()
elif (a==4):
exit()
else:
print('error')