JES 密码删除空格和标点符号



我有以下代码,输出如下。我想知道如何更改代码以获得没有z的答案。换句话说,我需要它忽略空格/空格和标点符号,以便最终输出sdfqfqeshqs

def buildCipher(key):
alpha = "abcdefghijklmnopqrstuvwxyz"
rest = ""
for letter in alpha:
if not (letter in key):
rest = rest + letter
print key + rest
def encode2(string, alpha2):
alpha = "abcdefghijklmnopqrstuvwxyz"
secret = ""
for letter in string:
index = alpha.find(letter)
secret = secret+alpha2[index]
print secret

buildCipher("earth")结果是earthbcdfgijklmnopqsuvwxyz.

encode2('this is a test', "earthbcdfgijklmnopqsuvwxyz")结果sdfqzfqzezshqs

如果letter不在alpha中,则alpha.find(letter)返回-1。alpha2[-1]alpha2的最后一封信.因此,如果该字母的索引为 -1,则只需跳过该字母。喜欢这个:

def encode2(string, alpha2):
alpha = "abcdefghijklmnopqrstuvwxyz"
secret = ""
for letter in string:
index = alpha.find(letter)
if index != -1:
secret = secret + alpha2[index]
print secret

相关内容

  • 没有找到相关文章

最新更新