본문 바로가기
> 알고리즘 문제 풀이/프로그래머스

lv1-시저 암호 (python, 파이썬)

by bky373 2020. 10. 22.
""" 나의 풀이 """
def solution(s, n):
    uppers = [ s for s in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
    lowers = [ s for s in 'abcdefghijklmnopqrstuvwxyz']
    ans = ''
    for x in s:
        if x == ' ':
            ans += ' '
        else:
            if x.isupper():
                ans += uppers[(uppers.index(x)+n)%26] 
            else:
                ans += lowers[(lowers.index(x)+n)%26]
    return ans
​

댓글