题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
# 收集原始密码 password_input = input() # 将字母和数字进行mapping keypad_mapping = { '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', '0': '0', '1': '1', '2': '2', '3': '3','4': '4', '5': '5', '6': '6', '7': '7','8': '8', '9': '9' } # 初始化一个空的string transformed_password = '' # 将input中每个字符都循环一遍 for char in password_input: if char.islower(): # If the character is lowercase transformed_password += keypad_mapping[char] # Map directly to number elif char.isupper(): # If the character is uppercase if char == 'Z': transformed_password += 'a' # Wrap 'Z' to 'a' else: next_char = chr(ord(char.lower()) + 1) # Convert to lowercase and shift transformed_password += next_char else: transformed_password += char # Leave digits and other characters unchanged # 输出加密后代码 print(transformed_password)