728x90
def solution(s, n):
    answer = ''
    alpha1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    alpha2 = 'abcdefghijklmnopqrstuvwxyz'   
    for i in range(len(s)):
        if s[i].isupper():
            answer += (alpha1[(alpha1.find(s[i])+n)%26])
        elif s[i].islower():
            answer += (alpha2[(alpha2.find(s[i])+n)%26])
        else:
            answer += ' '
    return answer
def solution(s, n):
    alpha1 = 'abcdefghijklmnopqrstuvwxyz'
    alpha2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    answer = ''
    for i in s:
        if i.isalpha():
            if i.islower():
                answer += chr((ord(i) - ord("a") + n) % 26 + ord("a"))
            else:
                answer += chr((ord(i) - ord("A") + n) % 26 + ord("A"))
        else:  
            answer += ' '
    return answer
def solution(s, n):
    alpha1 = 'abcdefghijklmnopqrstuvwxyz'
    alpha2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    answer = ''
    for i in range(len(s)):
        if s[i] == ' ':
            answer += ' '
        if 'a' <= s[i] <= 'z':
            answer += alpha1[(ord(s[i])-97+n)%26]
        if 'A' <= s[i] <= 'Z':
            answer += alpha2[(ord(s[i])-65+n)%26]    
    return answer
반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기