Caesar Cipher
Medium · 55 XPShift every lowercase letter in "hello world" forward by 3 (wrapping z→c), keep spaces, and print the result.
Target output
khoor zruog
Blank · autosaved
PYcaesar-cipher.py
chr((ord(ch) - ord('a') + shift) % 26 + ord('a')) for letters; keep spaces as-is.
message = "hello world"
shift = 3
result = ""
for ch in message:
if ch == " ":
result += ch
else:
result += chr((ord(ch) - ord("a") + shift) % 26 + ord("a"))
print(result)
Run your code to check it…