Python 编写简易东北方言小词典

代码目录下创建note.txt,内容:
噶哈:有什么事
磕趁:难看
卡了:摔倒,栽跟头了
埋汰:脏
上该里溜达:上街上,到街里闲逛。
唠嗑:谈话,聊天
白唬:瞎说,说话不着边际,能说
稀罕:喜欢
贼:很,特别
犊子:混蛋
扯犊子:闲扯、不干正经事
得瑟:不务正业,爱出风头
整个浪儿:全部
善茬子:软弱可欺的人
赛脸:不听话
膈应:讨厌,不喜欢
嘎咕:做事与众不同
图鄙:被人骗还不知道
麻溜:快点
打狼:最后一名
尿性:有骨气,厉害
老鼻子:多
毛楞三光:做事不稳重
欠登儿:到处添乱的人
老蒙咔吃眼:年纪大了,不受尊重
二异子:不男不女
吭吃瘪肚:说不明白
import winsound
import win32com
from win32com.client import Dispatch, constants
import random
import time
speak_out = win32com.client.Dispatch('sapi.spvoice')
lang={
    
    }


def view():                                    # 按字典顺序输出方言
    for key,value in lang.items():
        print(key,":",value)                   # 按字典顺序显示方言   
        speak(key+"     "+value)               # 按字典顺序语音播放方言
        time.sleep(1)                          # 循环间隔时间为1秒钟
def speak(str):                                # 按播放语音
    speak_out.speak(str)                       # 输出方言解释
    winsound.PlaySound(str,winsound.SND_ASYNC)   # 输出结束音
with open("note.txt","r",encoding='UTF-8') as file: # 读取文件中的方言给字典
    while True:
       line = file.readline()
       if line =='':            
           break
       group=line.split(":")           # 按“:”分割字符串
       lang[group[0]]=group[1] 
print("    东北方言\n")
print("说明:输入“q”退出系统;输入“s”按顺序输出并朗读词典内容。")
while True:
    word=input("请输入要查找的东北方言:").strip()
    if word.lower()=="q":
        break
    if word.lower()=="s":
        view()
    else:
        note=lang.get(word,"no")
        if note!="no":
            print(word,":",note)
            speak(word+":    "+note)
        else:
            print("没有检索到相关东北方言!")

猜你喜欢

转载自blog.csdn.net/Yuyu920716/article/details/111188632