我正在尝试使用 python 制作凯撒密码,这就是我能做到的:
alphabet = ['abcdefghijklmnopqrstuvwxyz']
def create(shift):
dictionary={}
emptylist=[]
int(shift)
for x in alphabet:
emptylist.append(x)
code = ""
for letters in emptylist:
code = code + chr(ord(letters) + shift)
dictionary[letters]=code
return dictionary
它可以让我输入我的班次值,然后打印:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
create(2)
File "C:/Users/Pete/Documents/C- Paisley/A-Level/Computing/dictionarytolist.py", line 11, in create
code = code + chr(ord(letters) + shift)
TypeError: ord() expected a character, but string of length 26 found
最终产品应该是打印移位的字母。