Decoder Program
String Manipulation (Do after Pylatin in codecademy)
Write a program to decode this sentence.
Write a program to code a regular sentence into jibberish using your personal key similar or different than the one above.
Write a program to code a regular sentence into jibberish using your personal key similar or different than the one above.
Hint
ROT13 is a weak form of encryption that involves “rotating” each letter in a word by 13 places. To rotate a letter means to shift it through the alphabet, wrapping around to the beginning if necessary, so ’A’ shifted by 3 is ’D’ and ’Z’ shifted by 1 is ’A’.
Write a function called code_word that takes a string and an integer as parameters, and that returns a new string that contains the letters from the original string “rotated” by the given amount.
For example, “cheer” rotated by 7 is “jolly” and “melon” rotated by -10 is “cubed”.
You might want to use the built-in functions ord, which converts a character to a numeric code, and chr, which converts numeric codes to characters.
import string
def rotate_letter(letter, n):
### Rotates a letter by n places. Does not change other chars.
### letter: single-letter string
### n: int
### Returns: single-letter string
def rotate_word(word, n):
"""Rotates a word by n places.
word: string
n: integer
Returns: string """
print rotate_word('cheer', 7)
print rotate_word('melon', -10)
print rotate_word('sleep', 9)
Write a function called code_word that takes a string and an integer as parameters, and that returns a new string that contains the letters from the original string “rotated” by the given amount.
For example, “cheer” rotated by 7 is “jolly” and “melon” rotated by -10 is “cubed”.
You might want to use the built-in functions ord, which converts a character to a numeric code, and chr, which converts numeric codes to characters.
import string
def rotate_letter(letter, n):
### Rotates a letter by n places. Does not change other chars.
### letter: single-letter string
### n: int
### Returns: single-letter string
def rotate_word(word, n):
"""Rotates a word by n places.
word: string
n: integer
Returns: string """
print rotate_word('cheer', 7)
print rotate_word('melon', -10)
print rotate_word('sleep', 9)