题解 | #简单密码#

简单密码

https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac

inp0 = input().strip()
result_str = ''

for char in inp0:
    if char.islower():
        if char in 'abc':
            result_str +='2'
        elif char in 'def':
            result_str +='3'
        elif char in 'ghi':
            result_str +='4'
        elif char in 'jkl':
            result_str +='5'
        elif char in 'mno':
            result_str +='6'
        elif char in 'pqrs':
            result_str +='7'
        elif char in 'tuv':
            result_str +='8'
        else:
            result_str +='9'
    elif char.isupper():
        new = chr((ord(char.lower())-ord('a') + 1 ) % 26 + ord('a'))
        #print(new)
        result_str += new
    else:
        result_str +=char
print(result_str)

用了一个繁琐的方法但是排除了单独判断Z的情况

#23届找工作求助阵地#
全部评论

相关推荐

面了100年面试不知...:小天才g了,但是天才还在
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务