def encryption(code):
encrypted = ''
for c in code:
if c == 'a':
encrypted = encrypted + '@'
elif c == 'e':
encrypted = encrypted + '()'
elif c == 'h':
encrypted = encrypted + '#'
elif c == 'l':
encrypted = encrypted + '1'
elif c == 'r':
encrypted = encrypted + '+'
elif c == 's'
encrypted = encrypted + '$'
elif c == 'v'
encrypted = encrypted + '^'
elif c == 'x'
encrypted = encrypted + '*'
#here you can add other characters that need to be encrypted in elif blocks.
else:
encrypted = encrypted + c
return encrypted
你不能用替换?很好,因为您应该使用
translate
。在不过,我觉得你的讲师希望你学习如何迭代明文,查找正确的值,并将其添加到累加器字符串中。伪代码:
^{pr2}$我会做一些类似的事情:
但是如果你不理解就把它交上来,我相信你的老师会让你失望的!在
代码:
测试:
^{pr2}$相关问题 更多 >
编程相关推荐