英語差就閒來無事用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("輸入格式錯誤,重新輸入!!")