日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python如何制作英文字典

系統 2404 0

本文實例為大家分享了python制作英文字典的具體代碼,供大家參考,具體內容如下

功能有添加單詞,多次添加單詞的意思,查詢,退出,建立單詞文件。

            
keys=[]
dic={}
def rdic():
  fr = open('dic.txt','r')  
  for line in fr:
    line = line.replace("\n",'')
    v = line.split(':')
    dic[v[0]] = v[1]
    keys.append(v[0])
  fr.close()
def centre():
  n = input("請輸入進入相應模塊(添加、查詢、退出):")
  if n == "添加":
    key= input("plsease input English:")
    if key not in keys:
      value=input("please input Chinese:")
      dic[key]=value
      keys.append(key)
    else :
      t=input("如果添加新的意思請輸入 Y,否則輸入N:")
      if ( t=='Y'):
        temp=""
        temp=temp+dic[key]
        key1= input("請輸入中文")
        temp=temp+","+key1
        print(temp)
        #keys.append(temp)
        dic[key]=temp
        print(dic)
        return 0
      else:
        return 0
  elif n== "查詢":
    key= input("plsease input English:")
    print(keys)
    print(dic)
    if key not in keys:
      print("the english not in the dic.")
    else :
      print(dic[key])
  elif n == "退出" :
    return 1
  else :
    print("輸入有誤")
    return 0
def wdic():
  #print("!")
  with open('dic.txt','w') as fw:
    for k in keys:
      fw.write(k+':'+dic[k]+'\n')
def main():
  rdic()
  while True:
    print(keys)
    print(dic)
    n=centre()
    print(keys)
    print(dic)
    if n==1:
      break
    if n==0:
      continue
  wdic()
main()
          

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 邢台市| 乐山市| 江川县| 汶川县| 桂阳县| 山东| 贵南县| 东乌珠穆沁旗| 邮箱| 德令哈市| 洪雅县| 宜都市| 沧州市| 高台县| 湖北省| 蓬溪县| 乌海市| 新野县| 惠来县| 西宁市| 丹凤县| 大宁县| 临西县| 洪泽县| 高要市| 夏邑县| 金寨县| 石家庄市| 盱眙县| 斗六市| 云林县| 桃源县| 平乐县| 平阳县| 夏河县| 建始县| 农安县| 南部县| 阿拉善盟| 永州市| 阿图什市|