word小程式

www.dan發表於2020-09-30
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')
  • (借鑑AIY…)www.dan

相關文章