简答题
偏难
#4740
破译密码:经过研究,该密码的加密规律如下: 1)原文中所有的字符都在字母表中被循环左移了三个位置(dec -> abz); 2)逆序存储(abcd -> dcb…
破译密码:经过研究,该密码的加密规律如下:
1)原文中所有的字符都在字母表中被循环左移了三个位置(dec -> abz);
2)逆序存储(abcd -> dcba );
3)大小写反转(abXY -> ABxy)。
输入:一个加密的字符串。(长度小于50且只包含大小写字母)
输出:输出解密后的字符串。
根据上述算法思想,补全下列代码。
输入输出示例:输入:djiAHYhSju,输出:XMvKbkdLMG
a=input() a=list(a) newList1=[] newList2=[] for i in a: num=ord(i) if num >=120 and num<=122: num= ① elif num>=88 and num<=90: num=num-23 else: num = ② c=chr(num) newList1.append(c) ③ for i in newList1: if i.isupper(): newList2.append( ④ ) if i.islower(): newList2.append(i.upper()) for i in newList2: print(i,end='')
答案与解析
正确答案:<pre class="brush:python;toolbar:false">a=input()
a=list(a)
newList1=[]
newList2=[]
for i in a:
num=ord(i)
if num >=120 and num<=122:
num=num-23
elif num>=88 and num<=90:
num=num-23
else:
num = num + 3
c=chr(num)
newList1.append(c)
newList1.reverse()
for i in newList1:
if i.isupper():
newList2.append(i.lower())
if i.islower():
newList2.append(i.upper())
for i in newList2:
print(i,end='')</pre>
解析
(1)num-23 或等效答案; (2分)
(2)num + 3 或等效答案; (2分)
(3)newList1.reverse() 或等效答案; (3分)
(4)i.lower() 或等效答案。(3分)