Advent of Python 2026Starts 1 Dec →

    Day 12Caesar Cipher

    Mediumstringsord-chr

    Write caesar(text, shift) that moves every letter in text forward by shift places in the alphabet, wrapping from z back to a.

    caesar("Hello, World!", 3) returns "Khoor, Zruog!".

    Examples

    Example 1
    >>> caesar("Hello, World!", 3)
    "Khoor, Zruog!"
    Example 2
    >>> caesar("xyz", 2)
    "zab"

    Good to know

    • Keep capitals as capitals and lowercase as lowercase. Leave anything that is not a letter unchanged.
    • shift can be negative (to decrypt) or larger than 26.

    Run examples checks the 2 examples above. Submit runs all 7 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write caesar in the editor, then run the examples. Use print() freely: its output is shown for each test.