我最后一次出现此错误时,有人建议使用替换,但我尝试了但是它没有用,
错误:
line 11, in replace
output_string = input_string.translate(rot)
TypeError: expected a string or other character buffer object
和我的代码
l = list('abcdefghijklmnopqrstuvwxyz')
rot = dict()
def generate_rotated_dictionary(n):
rot = dict((c, chr(97 + ((ord(c)-97 + n)%26) )) for c in l)
def replace(input_string):
for n in range(1, 26):
generate_rotated_dictionary(n)
output_string = input_string.translate(rot)
print(output_string)
rot.clear()
while True:
input_string = raw_input("Wat wilt u de-crypten?\n")
replace(input_string)
提前谢谢