题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import sys
st = input()
letter = [chr(x) for x in range(97,123,1)] #小写字母
LETTER = [x.upper() for x in letter] #大写字母
le2num = dict(a=2,b=2,c=2,d=3,e=3,f=3,g=4,h=4,i=4,j=5,k=5,l=5,m=6,n=6,o=6,p=7,q=7,r=7,s=7,t=8,u=8,v=8,w=9,x=9,y=9,z=9) #转换字典
res = '' #结果字符串初始化
for i in range(len(st)): #对字符串逐位加密
if str(st[i]) in LETTER: #大写字母转小写并并向前移位,注意Z转a
res += letter[(LETTER.index(st[i])+1)%26]
elif str(st[i]) in letter: #小写字母按照转换字典加密
res += str(le2num.get(st[i]))
else:
res += st[i]
print(res) #逐个字符拼接后输出
查看15道真题和解析