py_whisper_cipher

Código comentado línea a línea y paso a paso:

Entregas: py_whisper_cipher.py con whisper_cipher(text, shift). Rank 03 · nivel 6.

Qué pide (en palabras normales)

Subject (enunciado original)
Write a function that creates a Caesar cipher by shifting letters in a
string by a given amount.
Non-alphabetic characters should remain unchanged.
The shift can be negative (shift left).

Expected file: py_whisper_cipher.py
Function signature:
def whisper_cipher(text: str, shift: int) -> str:

Examples:
whisper_cipher("hello", 3)
=> "khoor"
whisper_cipher("Hello World!", 1)
=> "Ifmmp Xpsme!"
whisper_cipher("xyz", 3)
=> "abc"
whisper_cipher("ABC123def", 5)
=> "FGH123ijk"
whisper_cipher("", 10)
=> ""
whisper_cipher("abc", -3)
=> "xyz"

La fórmula

chr((ord(ch) - ord("a") + shift) % 26 + ord("a"))

Tres pasos: a posición 0..25, sumo y hago módulo 26, y vuelvo a letra. Para mayúsculas la misma con "A". El módulo de Python con negativos devuelve siempre un valor en 0..25 (-3 % 26 == 23), así que el shift negativo no necesita ningún caso especial.

Trampas