题解 | #简单密码#

简单密码

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

a = input()

def func(x):
    if x in ['a','b','c']:
        return '2'
    elif x in ['d','e','f']:
        return '3'
    elif x in ['g','h','i']:
        return '4'
    elif x in ['j','k','l']:
        return '5'
    elif x in ['m','n','o']:
        return '6'
    elif x in ['p','q','r','s']:
        return '7'
    elif x in ['t','u','v']:
        return '8'
    else:
        return '9'

def func_2(x):
    return chr(ord(x.lower())+1)

for i in range(len(a)):
    if 'a' <= a[i] <= 'z':
        a = a[:i]+func(a[i])+a[i+1:]
    if 'A' <= a[i] <= 'Y':
        a = a[:i]+func_2(a[i])+a[i+1:]
    if a[i] == 'Z':
        a = a[:i]+'a'+a[i+1:]

print(a)
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务