가이드라인
학습 자료
가이드라인

카이사르 암호 - 문제 풀이

카이사르 암호를 파이썬으로 구현한 2가지 방법을 확인해 보세요.


방법 1
def solution(text, shift): alphabet = 'abcdefghijklmnopqrstuvwxyz' result = '' for char in text: if char.isalpha(): index = alphabet.index(char.lower()) shifted_index = (index + shift) % 26 shifted_char = alphabet[shifted_index] result += shifted_char.upper() if char.isupper() else shifted_char else: result += char return result

사용 예시

입출력 예시
result = solution("abc", 3) print(result) # 출력: "def"

가이드라인

AI 튜터

배포

디자인

업로드

수업 노트

즐겨찾기

도움말