• 欢迎光临~

7-6 sdut-字母替换

开发技术 开发技术 2022-05-29 次浏览

方法一:使用list

judge = []
for i in range(26):
    judge.append( chr(65+25-i) )
# print(judge)
n= input()
n= [judge[ord(i)-65] if 'A'<=i<='Z' else i for i in n]
print(''.join(n))

方法2:使用map

judge = {}
for i in range(26):
    judge[chr(65+i)]=chr(65+25-i)
# print(judge)
n= input()
n= [judge[i] if 'A'<=i<='Z' else i for i in n]
print(''.join(n))
程序员灯塔
转载请注明原文链接:7-6 sdut-字母替换
喜欢 (0)