题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
while True:
try:
mima = input()
list1 = list(mima)
x =len(list1)
for i in range(x):
if list1[i].isupper() and list1[i] != 'Z': #先判断字符是大写字母且该字符不能是大写的Z
list1[i] = chr(ord(list1[i].lower())+1) #先用lower函数将大写字改为小写字母,然后使用ord函数将该小写字母的ASC11码得到,再加上1就是后移一位
elif list1[i] == 'Z': #然后使用chr函数将后移的字母的ASC11码变为 Unicode 字符,也就是小写字母
list1[i] = 'a' #如果判断的大写字母是Z就变为小写的a
elif list1[i] in 'abc': #以下就是将小写字母对应变为数字
list1[i] = '2'
elif list1[i] in 'def':
list1[i] = '3'
elif list1[i] in 'ghi':
list1[i] = '4'
elif list1[i] in 'jkl':
list1[i] = '5'
elif list1[i] in 'mno':
list1[i] = '6'
elif list1[i] in 'pqrs':
list1[i] = '7'
elif list1[i] in 'tuv':
list1[i] = '8'
elif list1[i] in 'wxyz':
list1[i] = '9'
print(''.join(list1)) #变换玩的字符是在列表中的,然后用join函数将其进行拼接
except:
break
try:
mima = input()
list1 = list(mima)
x =len(list1)
for i in range(x):
if list1[i].isupper() and list1[i] != 'Z': #先判断字符是大写字母且该字符不能是大写的Z
list1[i] = chr(ord(list1[i].lower())+1) #先用lower函数将大写字改为小写字母,然后使用ord函数将该小写字母的ASC11码得到,再加上1就是后移一位
elif list1[i] == 'Z': #然后使用chr函数将后移的字母的ASC11码变为 Unicode 字符,也就是小写字母
list1[i] = 'a' #如果判断的大写字母是Z就变为小写的a
elif list1[i] in 'abc': #以下就是将小写字母对应变为数字
list1[i] = '2'
elif list1[i] in 'def':
list1[i] = '3'
elif list1[i] in 'ghi':
list1[i] = '4'
elif list1[i] in 'jkl':
list1[i] = '5'
elif list1[i] in 'mno':
list1[i] = '6'
elif list1[i] in 'pqrs':
list1[i] = '7'
elif list1[i] in 'tuv':
list1[i] = '8'
elif list1[i] in 'wxyz':
list1[i] = '9'
print(''.join(list1)) #变换玩的字符是在列表中的,然后用join函数将其进行拼接
except:
break