题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
def trans_password(old_password: str) -> str: old_password = [i for i in old_password] dict_9 = {'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} new_password = '' for i in old_password: if ord('a') <= ord(i) <= ord('z'): # 小写转化为数字 new_password += str(dict_9[i]) elif ord('A') <= ord(i) <= ord('Y'): # 大写转化为数字 temp = chr(ord(i) + 1).lower() new_password += temp elif i == 'Z': new_password += 'a' else: new_password += i return new_password print(trans_password(input()))