Guidelines

카이사르 암호 - 문제 풀이

카이사르 암호를 파이썬으로 구현한 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"

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help