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
반응형
'전.py' 카테고리의 다른 글
프로그래머스 스킬트리 (level 2) (0) | 2021.01.01 |
---|---|
프로그래머스 주식가격 (level 2) (0) | 2020.12.31 |
프로그래머스 행렬 곱셈 (level 2) (0) | 2020.12.30 |
프로그래머스 124 나라의 숫자 (level 2) (0) | 2020.12.30 |
프로그래머스 프린터 (level 2) (0) | 2020.12.30 |