我正在做一个作业,它要求我使用字典的.get方法来填充下面函数中的空格。我遇到的问题是,当我尝试使用cipher.get()方法时,我不知道要通过键:值对的方法传递什么。基本上,如果在字典中找到加密的字母,我希望.get方法返回它,如果在字典中找不到,则返回原始字符。
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
cipher = {letters[i]: letters[(i-3) % len(letters)] for i in range(len(letters))}
def transform_message(message, cipher):
tmsg = ''
for c in message:
tmsg = tmsg + ___
return tmsg
发布于 2021-11-02 10:26:46
在.get()
函数中,您需要将c
作为参数传递,以便像这样从c
获取加密字母:
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
cipher = {letters[i]: letters[(i-3) % len(letters)] for i in range(len(letters))}
def transform_message(message, cipher):
tmsg = ''
for c in message:
tmsg += cipher.get(c,c)
return tmsg
https://stackoverflow.com/questions/69815271
复制