fork download
  1. def caesar(code, shift):
  2. ''' (str, int) -> str
  3. Shift every letter in the code by the integer 'shift'.
  4. >>> caesar('ABC', 2)
  5. CDE
  6. >>> caesar('a b c', 4)
  7. e f g
  8. '''
  9. decipher = ''
  10. for char in code:
  11. if 65<=ord(char)<=90:
  12. decipher = decipher + chr((ord(char) - 65 + shift)%26+65)
  13. if 97<=ord(char)<=122:
  14. decipher = decipher + chr((ord(char) - 97 + shift)%26+97)
  15. else:
  16. decipher += char
  17. return decipher
  18. print(caesar('ABC', 2))
  19. print(caesar('a b c', 4))
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
CADBEC
e f g