凯撒密码
题目
代码
def KSMM(convertstr):
for i in range(len(convertstr)):
if convertstr[i] != ' ':
if (ord(convertstr[i])>=65 and ord(convertstr[i])< 77)
or (ord(convertstr[i])>=97 and ord(convertstr[i])< 110):
convertstr[i] = chr(ord(convertstr[i]) + 13)
elif (ord(convertstr[i])>= 77 and ord(convertstr[i])<= 90)
or (ord(convertstr[i])>= 110 and ord(convertstr[i])<= 122):
convertstr[i] = chr(ord(convertstr[i]) - 13)
return ''.join(convertstr)
alist = list(input("Enter a string:\n"))
afterstr = KSMM(alist)
print(afterstr)
输入
The Zen of Python
输出
Gur Mra bs Clguba