[프로그래머스] 시저 암호Lv.1

나의 풀이

def solution(s, n):
    answer = ""
    for i in s:
        char_code = ord(i)
        if i.isspace():
            answer += i
        elif i.islower():
            answer += chr((char_code - ord('a') + n) % 26 + ord('a'))
        elif i.isupper():
            answer += chr((char_code - ord('A') + n) % 26 + ord('A'))
    return answer

0개의 댓글