Py学习  »  Python

python背单词小程序

AiY.. • 3 年前 • 170 次点击  

英语差就闲来无事用python写一个背单词的小程序,英语不好的博友们可以参考参考,哈哈~~~哈哈哈哈哈

程序代码:

import random as t
#创建单词序列
words=("easy","difficult","answer","continue")
zi=("容易","困难","回答","继续")
hanzi={ "easy":"容易", "difficult":"困难","answer":"回答", "continue":"继续","blue":"蓝色"}
yin={"容易":"easy","困难":"difficult","回答":"answer","继续":"continue","蓝色":"blue"}
def jiemian():
    print("""
                     欢迎来到背单词
        根据English回答汉语或者根据汉语回答English
        -------------------------------------------
                    1.English——>汉语
                    
                    2.汉语——>English
                    
                    3.单词列表
                    
                    4.退出系统
""")
#######Zhang######  English——>汉语   ################################
    
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("对不起,不正确。")
            n=n+1
            print('\n——>正确率:%.2f'%(m/(n+m)))
            guess=input("继续输入:").strip()
        if guess==hanzi[word]:
             print("真棒!答对了!!")
             m=m+1
             print('\n——>正确率:%.2f'%(m/(n+m)))
        iscontinue=input("\nn\是否继续(Y/N):")
        
###############  汉语——>English   #########wei####################

def hanyiy():
    n=0;
    m=0;
    su=0;
    iscontinue="y"
    while iscontinue=="y" or iscontinue=="Y":
        hz=t.choice(zi)
        print("随机生成在汉语:")
        print


    
(">------>   "+hz)
        guess=input("\n输入Ehglish: ").strip()
        while guess!=yin[hz]:
            print("对不起,不正确。")
            n=n+1
            print('\n——>正确率:%.2f'%(m/(n+m)))
            guess=input("继续输入:").strip()
        if guess==yin[hz]:
            print("真棒!答对了!!")
            m=m+1
            print('\n——>正确率:%.2f'%(m/(n+m)))
        iscontinue=input("\nn\是否继续(Y/N):")

####bu##########################################################

def lib():
    print("************************")
    print("\n")
    for i in range (len(words)):
        print(words[i],"   ",zi[i],"\n")
    print("\n")
    print("************************")
    a=input("输入 1 背诵单词结束——>: ")


###################################################################
        
while True:
    jiemian()
    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("输入格式错误,重新输入!!")
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/73830
 
170 次点击