题解 | #简单密码#简单粗暴
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
while True: try: pw = input() res = '' for ch in pw: if ord('a') <= ord(ch) <= ord('c'): ch = '2' elif ord('d') <= ord(ch) <= ord('f'): ch = '3' elif ord('g') <= ord(ch) <= ord('i'): ch = '4' elif ord('j') <= ord(ch) <= ord('l'): ch = '5' elif ord('m') <= ord(ch) <= ord('o'): ch = '6' elif ord('p') <= ord(ch) <= ord('s'): ch = '7' elif ord('t') <= ord(ch) <= ord('v'): ch = '8' elif ord('w') <= ord(ch) <= ord('z'): ch = '9' elif ch == 'Z': ch = 'a' elif ord('A') <= ord(ch) <= ord('Y'): ch = chr(ord(ch.lower()) + 1) res += ch print(res) except: break
简单粗暴,就是一长串判断
似乎小写字母转换成数字的操作交给字典会更好