# This program performs a basic rotation cipher, # shifting each character in a string by a given amount. # Prints a rotation cipher of s, shifting each letter in the string # by the given number of positions in the alphabet. # pre: s consists entirely of lowercase letters from a-z # pre: -26 <= amount <= 26 def encode(s, amount): for letter in s: num = ord(letter) + amount # shift letter if num > ord('z'): # wrap around if needed num -= 26 elif num < ord('a'): num += 26 print(chr(num), end="") print() def main(): encode("hello", 3) encode("zerglings", 1) encode("afshmjoht", -1) encode("congratulations", 11) main()