본문 바로가기

TIL/Algorithm

[프로그래머스] 시저암호(easy)

반응형

def solution(s, n):
    answer = ''
    for i in s:
        if ord(i) == 32:
            answer += i
        else:
            if ord(i) + n > 122 and 122>=ord(i) >= 97:
                answer += chr((ord(i)+n)%122 + 96)
            elif ord(i) + n > 90 and 90>=ord(i) >= 65:
                answer += chr((ord(i)+n)%90 + 64)
            else:
                answer += chr((ord(i)+n))
    return answer
반응형