我只想打印字母,但它会打印 ASCII 的特殊字符。我的代码:
import string
def caesar(shift):
alphabet = string.ascii_lowercase + string.ascii_uppercase
dict={}
emptylist=[]
int(shift)
for x in alphabet:
emptylist.append(x)
code = ""
for letters in emptylist:
code = chr(ord(letters) + shift)
dict[letters]=code
return dict
caesar(12)
我的输出:
'm': 'y', 'l': 'x', 'o': '{', 'n': 'z', 'q': '}', 'p': '|', 's ': '\x7f', 'r': '~', 'u': '\x81', 't': '\x80', 'w': '\x83', 'v': '\x82' , 'y': '\x85', 'x': '\x84', 'z': '\x86'
正确的输出:
'm':'y','l':'x','o':'a','n':'z','q':'c','p':'b','s ':'e','r':'d','u':'g','t':'f','w':'i','v':'h','y': 'k','x':'j','z':'l'