pyassistant

Caesar Shift Preserving Case

Write a function that applies a Caesar cipher shift to a string. Given a string s and an integer k, shift each alphabetic character in s forward by k positions in the alphabet, wrapping around if necessary. Preserve the case of letters (uppercase stays uppercase, lowercase stays lowercase) and leave non-letter characters unchanged. The shift k may be positive, negative, or larger than 26.

Example:

Input:
("Hello, World!", 3)
Output:
'Khoor, Zruog!'

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.