Python bootcamp · Lab 50

ROT13 cipher

mediumStrings12 minLesson: String Methods

Read the question, write Python on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read one line and print its ROT13 encoding: shift each letter by 13 places, wrapping within A–Z / a–z.

Non-letters stay unchanged. ROT13 twice returns the original.

Input. One line of text.

Output. The ROT13-encoded line.

Examples

Example 1
Input
Hello
Output
Uryyb
Example 2
Input
ABC xyz
Output
NOP klm
Hint
  1. Use codecs.encode(text, 'rot_13') or shift ord() by 13 with wrap.
  2. Keep non-letters as-is.
Show correct code

Peek only after you have tried. You can still Check your own version.

import codecs
print(codecs.encode(input(), 'rot_13'))
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.