派森(西南科大)#C. 摩斯密码翻译器

morse = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."]
digit = ['-----', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.']
punctuation = {'.': '.-.-.-', ':': '---...', ',': '--..--', ';': '-.-.-.', '?': '..- -..', '=': '-...-', "'": '.----.', '/': '-..-.', '!': '-.-.--', '-': '-....-', '_': '..--.-', '"': '.-..-.', '(': '-.--.', ')': '-.--.-', '$': '...-..-', '&': '·-···', '@': '.--.-.', ' ': ''}
text = str.upper(input())
for ch in text:
    if ord('A') <= ord(ch) <= ord('Z'):
        print(morse[ord(ch) - ord('A')], end=' ')
    elif ord('0') <= ord(ch) <= ord('9'):
        print(digit[ord(ch) - ord('0')], end=' ')
    elif ch in punctuation.keys():
        print(punctuation[ch], end=' ')
    else:
        print(ch, end=' ')

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是一个简单的微信机器人派森框架的代码示例,你可以根据需要进行修改和优化: ```python import itchat from threading import Thread from queue import Queue class WechatBot: def __init__(self): self.msg_queue = Queue() self.bot = itchat.new_instance() self.bot.auto_login(hotReload=True) self.bot.run(blockThread=False) self.friend_list = self.bot.get_friends() def send_msg(self, msg, to_user): self.bot.send(msg, toUserName=to_user) def handle_msg(self, msg): from_user = msg['FromUserName'] msg_type = msg['Type'] if msg_type == 'Text': content = msg['Text'] self.msg_queue.put((from_user, content)) def listen(self): @self.bot.msg_register(['Text', 'Picture', 'Recording', 'Attachment', 'Video']) def receive_msg(msg): self.handle_msg(msg) def run(self): listen_thread = Thread(target=self.listen) listen_thread.start() while True: if not self.msg_queue.empty(): from_user, content = self.msg_queue.get() # 处理消息并回复 reply = self.reply(content, from_user) self.send_msg(reply, from_user) def reply(self, msg, from_user): # 实现具体的自动回复逻辑 return "这是机器人自动回复的消息。" if __name__ == '__main__': bot = WechatBot() bot.run() ``` 以上代码实现了一个基本的微信机器人框架,它能够监听用户发送的消息并将其加入消息队列,然后在主线程中不断从消息队列中读取消息并进行处理和回复。你可以根据需要修改 `reply` 函数来实现具体的自动回复逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值